Azure: PowerShell模块已正确推送到工件存储库,但无法安装。

5
我的目的是配置一个私有源,以便在Azure Pipelines中使用我的PowerShell模块。
我按照此Microsoft指南逐步操作:https://learn.microsoft.com/en-us/azure/devops/artifacts/tutorials/private-powershell-library?view=azure-devops
我知道包已经从DevOps用户界面成功推送:enter image description here 以下代码(在我的开发机器上执行)证明了这个源和包都处于有效状态:
$patToken = "**************************************" | ConvertTo-SecureString -AsPlainText -Force
$credsAzureDevopsServices = New-Object System.Management.Automation.PSCredential("giacomo.stelluti@dev4side.com", $patToken)
Get-PSRepository
Find-Module -Repository PowershellAzureDevopsServices -Credential $credsAzureDevopsServices
Install-Module -Name Get-Hello -Repository PowershellAzureDevopsServices -Credential $credsAzureDevopsServices

这是输出结果:

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Untrusted            https://www.powershellgallery.com/api/v2
PowershellAzureDevopsS... Trusted              https://pkgs.dev.azure.com/dev4side/Dev4side%20-%20Intranet.ai/_packaging/iai-feed/nuget/v2

Name                       : Get-Hello
Version                    : 1.0.0
Type                       : Module
Description                : Package description
Author                     : dev4side
CompanyName                :
Copyright                  : Copyright 2020 Dev4Side SRL
PublishedDate              : 4/1/2020 11:28:48 AM
InstalledDate              :
UpdatedDate                :
LicenseUri                 :
ProjectUri                 : 
IconUri                    :
Tags                       : {devtest}
Includes                   : {Function, RoleCapability, Command, DscResource...}
PowerShellGetFormatVersion :
ReleaseNotes               : Summary of changes made in this release of the package.
Dependencies               : {}
RepositorySourceLocation   : https://pkgs.dev.azure.com/dev4side/Dev4side%20-%20Intranet.ai/_packaging/iai-feed/nuget/v2
Repository                 : PowershellAzureDevopsServices
PackageManagementProvider  : NuGet
AdditionalMetadata         : @{summary=Package description; releaseNotes=Summary of changes made in this release of the package.; copyright=Copyright      
                             2020 Dev4Side SRL; tags=devtest; PackageManagementProvider=NuGet; SourceName=PowershellAzureDevopsServices;
                             description=Package description; created=4/1/2020 11:28:48 AM +02:00; published=4/1/2020 11:28:48 AM +02:00;
                             developmentDependency=False; NormalizedVersion=1.0.0; downloadCount=0; lastUpdated=4/1/2020 11:28:48 AM +02:00;
                             Authors=dev4side; updated=2020-04-01T09:28:48Z; isLatestVersion=True; Listed=true; IsPrerelease=false;
                             isAbsoluteLatestVersion=True; packageSize=15279; lastEdited=4/1/2020 11:28:48 AM +02:00; requireLicenseAcceptance=False}     

但如果我尝试使用管理员账户安装该模块:

Install-Module -Name Get-Hello -Repository PowershellAzureDevopsServices -Credential $credsAzureDevopsServices

我得到:

PackageManagement\Install-Package : Unable to resolve package source 'https://pkgs.dev.azure.com/dev4side/Dev4side -
Intranet.ai/_packaging/iai-feed/nuget/v2'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.3\PSModule.psm1:9685 char:34
+ ... talledPackages = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (https://pkgs.de...i-feed/nuget/v2:String) [Install-Package], Exceptio
   n
    + FullyQualifiedErrorId : UnableToResolveSource,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

这个代码片段 中,列出了我已安装的模块清单。
我想补充说明:
nuget install Get-Hello

完美地工作:

Feeds used:
  https://api.nuget.org/v3/index.json
  https://pkgs.dev.azure.com/dev4side/Dev4side%20-%20Intranet.ai/_packaging/iai-feed/nuget/v3/index.json
  C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

Installing package 'Get-Hello' to 'C:\Temp'.
  GET https://api.nuget.org/v3/registration5-gz-semver2/get-hello/index.json
  NotFound https://api.nuget.org/v3/registration5-gz-semver2/get-hello/index.json 529ms
  GET https://pkgs.dev.azure.com/dev4side/eef92fe2-7e7f-4eb5-a62c-cc1dc2f2b440/_packaging/930b7fe7-4c85-435a-9945-733a3
0e1ea5b/nuget/v3/registrations2-semver2/get-hello/index.json
  OK https://pkgs.dev.azure.com/dev4side/eef92fe2-7e7f-4eb5-a62c-cc1dc2f2b440/_packaging/930b7fe7-4c85-435a-9945-733a30
e1ea5b/nuget/v3/registrations2-semver2/get-hello/index.json 1501ms


Attempting to gather dependency information for package 'Get-Hello.1.0.0' with respect to project 'C:\Temp', targeting
'Any,Version=v0.0'
Gathering dependency information took 26.03 ms
Attempting to resolve dependencies for package 'Get-Hello.1.0.0' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'Get-Hello.1.0.0'
Resolved actions to install package 'Get-Hello.1.0.0'
Retrieving package 'Get-Hello 1.0.0' from 'PowershellModules'.
Adding package 'Get-Hello.1.0.0' to folder 'C:\Temp'
Added package 'Get-Hello.1.0.0' to folder 'C:\Temp'
Successfully installed 'Get-Hello 1.0.0' to C:\Temp
Executing nuget actions took 119.62 ms

非常感谢您的任何帮助

2个回答

14

多年来,PackageManagement或PowerShellGet组件中存在一个错误,正是这个错误导致了这个问题。我遇到过相同的问题,并且可以证实,如果将存储库注册为PowerShell存储库并且作为软件包源,则它会正确地工作。

在使用最新的PackageManager 2.2.4.1时,我收到的错误消息几乎相同,我在此添加它以帮助其他人找到这个确切的消息:

C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.4.1\PSModule.psm1:9709 Zeichen:34

所以:

Register-PSRepository -Name DevOpsFeedPsRepo [...] -SourceLocation $artifactFeed
Register-PackageSource -Name DevOpsFeedPackageSource -Location "$artifactFeed" -ProviderName NuGet -SkipValidate 

我还可以确认,使用Azure Artifacts凭据提供程序后,第一次注册后就不需要每次都提供凭据。


谢谢你,Marco!我会尽力查看你所说的内容。 - gsscoder
1
可以确认,除了我之前执行的Register-PSRepository之外,Register-PackageSource也已经为我解决了这个问题。谢谢! - Mike Powell

1
我曾经也遇到过同样的问题,但是我找到了一个博客文章,它经历了相同的故障排除过程,并得出结论:如果在Install-Module期间不提供PAT代码,则无法对源进行身份验证并下载包。在我的测试中,我尝试了这个方法,它起作用了。
Install-Module -Repository PSModules -Name Get-Hello -Credentials $PSCredwithPAT

这将会非常好,如果它能够与我们注册的PowerShell存储库中的嵌入式凭据一起使用。但是没有这个,这似乎是最好的解决方案。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接