发布模块 "Get-PackageSource Unable to find repository 'ArtifactoryDev'" 错误。虽然 ArtifactoryDe​​v 存在

Publish-Module "Get-PackageSource Unable to find repository 'ArtifactoryDev'" error. Though ArtifactoryDev exists

无法将现有 Powershell 模块的更新发布到我们的 Artifact Store。

在我的脚本中,我注册了我的存储库和包源:

Register-PSRepository -Name ArtifactoryDev -SourceLocation $NuGetDevUrl -PublishLocation $NuGetDevUrl -InstallationPolicy Trusted -Credential $Cred
    Register-PackageSource -Name ArtifactoryDev -ProviderName NuGet -Location $NuGetDevUrl -Trusted -Credential $Cred

然后,在我的脚本接近尾声时,我尝试发布模块以更新我们在 Artifactory 中现有的模块:

    Publish-Module -Path $Module.Path -Repository $RepositoryName -NuGetApiKey "$($ArtifactoryUser):$($ArtifactoryToken)" -Credential $Cred -Force -ErrorAction Stop -Verbose -Debug

我收到以下错误

2019-06-27T12:12:24.2452350Z ##[error]PackageManagement\Get-PackageSource : Unable to find repository 'ArtifactoryDev'. Use Get-PSRepository to see all 
available repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet.1.5\PSModule.psm1:9360 char:35
+ ... ckageSources = PackageManagement\Get-PackageSource @PSBoundParameters
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...etPackageSource:GetPackageSource) [Get-PackageSource] 
   , Exception
    + FullyQualifiedErrorId : SourceNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageSource

要检查存储库是否存在,我想调用 获取 PackageSource -Name ArtifatoryDe​​v

我可以在结果中看到它:

Name                             ProviderName     IsTrusted  Location
----                             ------------     ---------  --------
ArtifactoryDev                   PowerShellGet    True        http://myremoterepo

我在发布功能方面遇到过类似的问题。您是否尝试在发布之前取消注册并重新注册回购协议?我发现这很管用。出于某种原因,发布模块会在发布之前对回购进行匿名调用以检查版本(我认为),如果回购是安全的(或不允许匿名身份验证),您可能会收到错误。通过在发布之前注销和重新注册回购协议,我发现它以某种方式绕过了匿名电话……不确定到底是为什么。