使用 Publish-Module 将 Powershell 模块发布到 VSTS 包管理

Publishing Powershell Modules to VSTS Package Management using Publish-Module

我正在尝试将我的 Powershell 模块发布到 VSTS 包管理提要。到目前为止我有:

$securePass = ConvertTo-SecureString -String $RepositoryPassword -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($RepositoryUsername, $securePass)


Write-Debug "Adding the Repository $RepositoryName"
Register-PSRepository -Name $RepositoryName -SourceLocation $RepositorySourceUri `
                            -PublishLocation $RepositoryPublishUri -Credential $cred `
                          -PackageManagementProvider Nuget -InstallationPolicy Trusted

$PublishParams = @{
    Path = $ModuleFolderPath
    ProjectUri = $ProjectUri
    Tags = $ModuleTags
    Repository = $RepositoryName
    NugetApiKey = $NugetApiKey
}

Publish-Module @PublishParams -Force -Verbose

但是,我收到以下错误:

Publish-PSArtifactUtility : Failed to publish module 'Framework.Logging': 'Publishing to a ******** package management feed 'https://xxx.pkgs.visualstudio.com/_packaging/PowershellModules/nuget/v2' requires it to be registered as a NuGet package source. Retry after adding this source
'https://xxx.pkgs.visualstudio.com/_packaging/PowershellModules/nuget/v2' as NuGet package source by following the instructions specified at 'https://go.microsoft.com/fwlink/?LinkID=698608''. At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet.1.2.0\PSModule.psm1:1227 char:17 + Publish-PSArtifactUtility -PSModuleInfo $moduleInfo ` + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : FailedToPublishTheModule,Publish-PSArtifactUtility

PSRepository 在创建时作为源 Uris 和发布 Uris 传递 https://xxx.pkgs.visualstudio.com/_packaging/PowershellModules/nuget/v2。关于我哪里出错的任何指示?

调用此命令以使用 NuGet.exe 工具添加包源:

  1. 下载Nuget.exe到文件夹
  2. 打开命令提示符并导航 (CD) 到该文件夹​​

命令:

.\nuget.exe sources add -name [sourcename, such as myPSModuleFeed] -source https://[account].pkgs.visualstudio.com/_packaging/[feedname]/nuget/v2 -username test -password [PAT] -storePasswordInClearText

关于个人访问令牌的文章:Authenticate access with personal access tokens for Team Services and TFS