【问题标题】:Unable to publish to Azure devops Nuget无法发布到 Azure devops Nuget
【发布时间】:2021-02-04 20:03:21
【问题描述】:

我已经构建了一个同时使用 PSGallery 和 Azure Devops 的模块(我有一个免费的 repo,我一直在使用它)。这是模块:https://www.powershellgallery.com/packages/xanderu.helpers/0.1.9

我遇到的问题是,当我尝试利用安全存储库时,我不断收到禁止错误。这是我调用模块的方式:

Publish-ToPSGallery -PSGalleryKey $PSGalleryKey `
    -secureRepoName 'PowershellAZDO' `
    -secureRepopublishApiKey $PATToken `
    -secureRepopublishApiURL "https://pkgs.dev.azure.com/$orgName/$projectName/_packaging/$feedName/nuget/v2/" `
    -secureRepoUser $secureRepoUser `
    -secureRepoPass $PATToken `
    -codePath .

它是一个非常严格的模块,但基本上是创建一个具有“私有”标签的模块(或脚本),它应该相应地发布到 PSGallery 或 AZDO。我确定这与我使用令牌和凭据(或 API 密钥)的方式有关。有谁知道我在这里做错了什么?

编辑:作为 xanderu.helpers 的一部分,有一个函数 new-powershelltemplate ,它将自动构建可用于发布管道的模块清单或脚本基线

附加编辑: 我还尝试了以下方法来推送到 myget nuget,它会推送但它不会使用 find-module -repository myget 找到模块:

Publish-ToPSGallery -PSGalleryKey $PSGalleryKey `
    -secureRepoName 'MyGet' `
    -secureRepopublishApiKey $nugetAPIKey `
    -secureRepopublishApiURL "https://www.myget.org/F/$feedName/api/v2" `
    -secureRepoUser $secureRepoUser `
    -secureRepoPass $secureRepoPass `
    -codePath .

编辑 #3 当我跑的时候,我做了更多的乱七八糟的事情

nuget.exe sources

运行脚本后,我可以看到 nuget 将 PowershellAZDO 作为源。然后我运行:

nuget push -Source "PowershellAZDO" -ApiKey AzureDevOps .\xanderu.helpers.0.1.9.nupkg

然后我被提示输入用户名和密码。当我输入用户名和 PATToken 时,它会推送包。这似乎是 Publish-Module 命令中的一个错误,但我不确定为什么。就像模块通过的 PSCredential 不被兑现一样。我不断挖掘,发现在PowerShellGet v2.2.5 PSModule.psm1文件中,有一个调用(第10990行):

Publish-PSArtifactUtility @PublishPSArtifactUtility_Params

实际上我确实在其中看到了 PSCredential 对象。我在 PowerShellGet 模块中添加了以下步骤,似乎可以解决这个问题......但这是它会出现的源代码中的一个错误(从第 6018 行开始):

        elseif ($NuGetExePath) {
            & $NuGetExePath sources update -Name $Repository -UserName $Credential.Username -Password $Credential.GetNetworkCredential().Password
            Publish-NugetPackage -NupkgPath $NupkgFullName -Destination $Destination -NugetApiKey $NugetApiKey -NugetExePath $NuGetExePath -Verbose:$VerbosePreference
        }

NuGet 版本:5.7.0.6726

PowerShell获取版本:2.2.5

【问题讨论】:

    标签: powershell azure-devops publishing


    【解决方案1】:

    这是由我正在使用的 Powershellget 模块 v 2.2.5 中的一个错误引起的。根本原因是因为 repo 没有传入密码,您需要将密码添加到 nuget 的配置中。这似乎在 PowerShellGet 的 3.0.0 版本中得到解决。我需要更新清单/模块以强制加载该版本的模块来解决问题。

    编辑:从头开始...看起来我认为这可行,但这是因为我的 nuget.exe 凭据被保留了。

    编辑2: 这可以正常工作,并且不需要拧紧核心模块。运行 Register-PSRepository 命令后,请确保同时运行以下命令,否则到 Azure Devops 的发布管道将不起作用。这是模块中的一个错误,因为它适用于其他地方。

    nuget sources update -Name $secureRepoParams.Name -UserName $secureRepoParams.Credential -Password $secureRepoParams.Credential.GetNetworkCredential().Password
    

    【讨论】:

    • 很抱歉造成误会,很高兴看到您的问题得到解决,您可以Accept it as an Answer,这对阅读此主题的其他社区成员会有所帮助。
    • 它实际上并没有解决。该问题在 3.0.0 中仍然存在,因此需要由模块所有者修复。我已经通过 PSGallery 向模块所有者提交了一条消息(但它看起来有些不活跃)。我可能只是将源代码作为私有模块部分拉入并修改到我的代码中,看看我是否可以让它以这种方式工作。
    猜你喜欢
    • 1970-01-01
    • 2019-03-26
    • 2020-01-30
    • 1970-01-01
    • 2021-05-06
    • 2021-04-17
    • 1970-01-01
    • 2020-08-01
    • 1970-01-01
    相关资源
    最近更新 更多