Publish-PSArtifactUtility无法解决发布时的模块依赖性,即使它们位于同一提要中

时间:2019-03-27 21:03:54

标签: powershell azure-devops nuget azure-pipelines azure-artifacts

我试图将PowerShell模块发布到Azure Artifacts,该模块依赖于同一Artifacts feed中承载的另一个模块。这个想法是,当我从提要中本地安装模块时,将自动安装正确版本的依赖项。问题是当我运行时:

Publish-Module -NuGetApiKey "{token}" -Path {path} -Repository "{ArtifactsFeedName}" -Verbose -ErrorAction Stop

我收到以下错误:

 Publish-PSArtifactUtility : PowerShellGet cannot resolve the module dependency '{dependency}' of the module 
 '{moduleWhichHasDependency}' on the repository '{ArtifactsFeed}'. Verify that the dependent module '{dependency}' 
 is available in the repository '{ArtifactsFeed}'. If this dependent module '{dependency}' is managed externally, 
 add it to the ExternalModuleDependencies entry in the PSData section of the module manifest.
 At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1190 char:17
 +                 Publish-PSArtifactUtility -PSModuleInfo $moduleInfo `
 +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [Publish-PSArtifactUtility], InvalidOperationException
+ FullyQualifiedErrorId : UnableToResolveModuleDependency,Publish-PSArtifactUtility

在清单中,像这样添加依赖项:

 RequiredModules = @( @{ModuleName = '{dependency}'; ModuleVersion = '1.0.4'; })

然后我尝试添加:

ExternalModuleDependencies = @( @{ModuleName = '{dependency}'; ModuleVersion = '1.0.4'; })

该模块已发布,但是当我在本地安装它时,它不会安装依赖项。

2 个答案:

答案 0 :(得分:0)

此问题似乎已在PowershellGet的最新版本(PSGallery中为2.2,我的计算机上安装的版本为1.0.1)中得到解决。 您还可以安装最新版本的PackageManagement(1.4.3与1.0.1)

请参阅:

在后续的Publish-Module / Script调用中添加了凭据参数。 #93 https://github.com/PowerShell/PowerShellGet/pull/93

将发布模块凭证参数传播到子功能#104 https://github.com/PowerShell/PowerShellGet/pull/104

为此:

Install-Module PowershellGet -Force #-Scope Current #if you don't want to login as Administrator

但是,我有一个问题要问:当您使用Azure Artifact feed调用发布模块时,如何不提供凭据?我知道它们应该存储在nuget.config文件中,但是每次都必须给它们。

Publish-Module -NuGetApiKey "{whatever}" -Credentials "{PSCredentials object}" -Path {path} -Repository "{ArtifactsFeedName}" -Verbose -ErrorAction Stop

答案 1 :(得分:0)

在@clientGOOG答案上进行扩展,我的版本是2.2.4.1,但是我遇到了同样的问题,我正在发布到myget,并通过使用预先认证的线程解决了这个问题。我确实没有不必必须添加ExternalModuleDependencies设置才能使此工作生效。

使用-Verbose标志,我注意到“查找”进程在放弃之前重试了3倍。

VERBOSE: Using the provider 'PowerShellGet' for searching packages.
VERBOSE: Using the specified source names : '{myrepo}'.
VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.
VERBOSE: The specified Location is 'https://{myorg}.myget.org/F/{myfeed}/api/v3/index.json' and PackageManagementProvider is 'NuGet'.
VERBOSE: Retry downloading 'https://{myorg}.myget.org/F/{myfeed}/api/v3/index.json' for '2' more times
VERBOSE: Retry downloading 'https://{myorg}.myget.org/F/{myfeed}/api/v3/index.json' for '1' more times
VERBOSE: Retry downloading 'https://{myorg}.myget.org/F/{myfeed}/api/v3/index.json' for '0' more times
VERBOSE: Total package yield:'0' for the specified package '{dependent module}'.

这是我修改后的代码,解决了该问题:

Register-PSRepository -Name {MyRepo} "https://{myorg}.myget.org/F/{myfeed}/auth/{apikey}/api/v2"

Publish-Module -Path ($module.path |Split-Path -Parent) -NuGetApiKey $APIKey -Repository {MyRepo} -Verbose -ErrorAction Stop

注意:它仍然需要发布时使用NuGetApiKey,但是我认为经过身份验证的提要将传递给失败的“查找”调用,这就是为什么它现在可以工作的原因。