【问题标题】:Using VSTS as PowerShell Gallery in Deployments在部署中使用 VSTS 作为 PowerShell 库
【发布时间】:2019-11-16 00:57:28
【问题描述】:

我的 VSTS 项目中有一个 PowerShell 模块的提要,我将它用作私人画廊,基于这篇文章: https://roadtoalm.com/2017/05/02/using-vsts-package-management-as-a-private-powershell-gallery/

当我们在机器上运行它时,一切都很好。 我需要这些模块作为发布过程的一部分,所以首要任务是注册这个 repo(如果它不存在),然后下载并安装每个模块的最新版本。 我的脚本的相关部分是:

Install-PackageProvider -Name NuGet -Confirm:$false -RequiredVersion 2.8.5.208
Get-PSRepository | Where-Object {$_.Name -eq "MyPrivateFeed" -or $_.SourceLocation -eq "https://myproject.pkgs.visualstudio.com/_packaging/MyPrivateFeed/nuget/v2"} | Unregister-PSRepository
Register-PSRepository -Name "MyPrivateFeed" -SourceLocation "https://myproject.pkgs.visualstudio.com/_packaging/MyPrivateFeed/nuget/v2" -InstallationPolicy Trusted
$PAT = $(System.AccessToken) | ConvertTo-SecureString -AsPlainText -Force
$VSTSCredentials = New-Object -TypeName PScredential("dummy", $PAT)
Find-Module -Name * -Repository MyPrivateFeed -Credential $VSTSCredentials | Install-Module -Credential $VSTSCredentials

发行版中的 PowerShell 任务失败并显示:

WARNING: Unable to find module repositories.
PackageManagement\Register-PackageSource : The property 'Values' cannot be 
found on this object. Verify that the property exists.
At C:\Program 
Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:4173 
char:17
+ ...     $null = PackageManagement\Register-PackageSource @PSBoundParamete ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Microsoft.Power...erPackageSource 
   :RegisterPackageSource) [Register-PackageSource], Exception
    + FullyQualifiedErrorId : PropertyNotFoundStrict,Microsoft.PowerShell.Pack 
   ageManagement.Cmdlets.RegisterPackageSource 

当我在 ISE/Console 上运行相同的脚本时,它可以在同一台机器上运行(当然,用实际的 PAT 替换令牌) 有人知道这里发生了什么吗?

我尝试将 -PackageManagementProvider NuGet 添加到 Register-PSRepository 但没有帮助

【问题讨论】:

    标签: powershell azure-devops


    【解决方案1】:

    我偶尔会看到“Register-PackageSource:在此对象上找不到属性‘值’。请验证该属性是否存在。”当当前没有为“PowerShellGet”包提供程序注册的包源(甚至没有默认“PSGallery”)。

    当当前用户的配置文件“%USERPROFILE%\AppData\Local\Microsoft\Windows\PowerShell\PowerShellGet\PSRepositories.xml”下存在空文件时,这似乎会发生。我不确定是什么原因导致创建了那个空文件,但在它被删除之前,即使是“Register-PSRepository -Default”命令也不会成功。

    删除文件确实可以解决错误并允许重新注册 PowerShellGet 包源。

    【讨论】:

      猜你喜欢
      • 2018-01-31
      • 1970-01-01
      • 2018-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-26
      • 2019-09-20
      • 1970-01-01
      相关资源
      最近更新 更多