Azure:无法安装正确推送到工件提要存储库的 PowerShell 模块

gss*_*der 3 powershell azure nuget

我的目的是配置一个私有源,以便能够在Azure Pipelines 中使用我的PowerShell模块。

我已经一步一步地遵循了这个Microsoft指南:https : //docs.microsoft.com/en-us/azure/devops/artifacts/tutorials/private-powershell-library?view=azure-devops

我知道包是从DevOps UI正确推送的: 在此处输入图片说明

以下代码(从我的开发机器执行)证明提要和包都处于有效状态:

$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
Run Code Online (Sandbox Code Playgroud)

这是输出:

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}     
Run Code Online (Sandbox Code Playgroud)

但是,如果我尝试使用以下命令安装模块(使用管理员帐户):

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}     
Run Code Online (Sandbox Code Playgroud)

我得到:

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
Run Code Online (Sandbox Code Playgroud)

这个要点中有我安装的模块列表。

我想补充一点:

Install-Module -Name Get-Hello -Repository PowershellAzureDevopsServices -Credential $credsAzureDevopsServices
Run Code Online (Sandbox Code Playgroud)

完美的作品:

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
Run Code Online (Sandbox Code Playgroud)

任何帮助真的很感激!

Mar*_*orm 9

多年来,某些 PackageManagement 或 PowerShellGet 组件中存在一个错误,这正是导致此问题的原因。我遇到了同样的问题,如果您将存储库注册为 PowerShell 存储库包源,则可以验证其是否正常工作。我使用最新的 PackageManager 2.2.4.1 得到的错误消息几乎相同,我只是在此处添加它以帮助其他人找到此确切消息:

C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.4.1\PSModule.psm1:9709 Zeichen:34
Run Code Online (Sandbox Code Playgroud)

所以:

Register-PSRepository -Name DevOpsFeedPsRepo [...] -SourceLocation $artifactFeed
Register-PackageSource -Name DevOpsFeedPackageSource -Location "$artifactFeed" -ProviderName NuGet -SkipValidate 
Run Code Online (Sandbox Code Playgroud)

我还可以确认,使用Azure Artifacts 凭据提供程序在首次注册后无需一直提供凭据。


小智 1

我遇到了同样的问题,但我发现一篇博客文章经历了相同的故障排除过程,并得出结论,如果在过程中不提供 PAT 代码,Install-Module它将无法对源进行身份验证并下载包。

我在测试中这样做了并且它有效:

Install-Module -Repository PSModules -Name Get-Hello -Credentials $PSCredwithPAT
Run Code Online (Sandbox Code Playgroud)

如果这与我们注册的 PowerShell 存储库上的嵌入式凭据一起使用,那就太好了。但如果没有这个,这似乎是最好的解决方案。