我的目的是配置一个私有源,以便在Azure Pipelines中使用我的PowerShell模块。
我按照此Microsoft指南逐步操作:https://learn.microsoft.com/en-us/azure/devops/artifacts/tutorials/private-powershell-library?view=azure-devops。
我知道包已经从DevOps用户界面成功推送:
以下代码(在我的开发机器上执行)证明了这个源和包都处于有效状态:
在 这个代码片段 中,列出了我已安装的模块清单。
我想补充说明:
我按照此Microsoft指南逐步操作:https://learn.microsoft.com/en-us/azure/devops/artifacts/tutorials/private-powershell-library?view=azure-devops。
我知道包已经从DevOps用户界面成功推送:
![enter image description here](https://istack.dev59.com/l463N.webp)
$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
非常感谢您的任何帮助!
Register-PSRepository
之外,Register-PackageSource
也已经为我解决了这个问题。谢谢! - Mike Powell