【问题标题】:Can we replace nuget.config file with command parameters?我们可以用命令参数替换 nuget.config 文件吗?
【发布时间】:2023-03-03 14:55:01
【问题描述】:

我正在开发一个在 Windows 自托管代理上运行的 Azure 管道。 我们配置了一个带有上游的 Artefact 提要以连接到 Nuget。 由于我们位于防火墙后面,这似乎是连接到 Nuget 的唯一方法。

我的管道正在使用这个 nuget.config 文件:

  <packageSources>
    <clear />
    <add key="FeedName" value="https://***.pkgs.visualstudio.com/***/_packaging/FeedName/nuget/v3/index.json" />
  </packageSources>

还有这个 YAML:

- task: NuGetAuthenticate@0
- task: CmdLine@2
  inputs:
    script: '"C:\dotnet\dotnet.exe" publish ${{ parameters.solutionToPublishPath }} -c ${{ parameters.buildConfiguration }} -o $(Build.BinariesDirectory)'

nuget.config 文件破坏了 TeamCity 中以前的管道! 为了在我处理新的同时保持旧的运行,我正在寻找一种将信息从 nuget.config 文件移动到脚本的方法。

有可能吗?

我试过这个:

- task: CmdLine@2
  inputs:
    script: '"C:\dotnet\dotnet.exe" add "src/project/project.API.csproj" package FeedName -s https://***.pkgs.visualstudio.com/***/_packaging/FeedName/nuget/v3/index.json'

我收到这条消息,这表明它试图直接访问 Nuget 但失败了,这就是我们使用提要的原因。

error: Unable to load the service index for source https://api.nuget.org/v3/index.json.
error:   Response status code does not indicate success: 302 (Moved Temporarily).

感谢您的帮助

【问题讨论】:

  • 您能否详细说明“nuget.config 文件破坏了 TeamCity 中以前的管道”?您的意思是 nuget.config 设置会影响其他构建吗?
  • 谢谢,我不是在 TeamCity 工作的人,但似乎当 nuget 文件中的 FeedName 转到 Azure 提要时,不允许访问 URL,他们永远无法成功TeamCity 更新了 nuget 包,因为这里的安全性非常严格,当时他们决定将 nuget 包复制到本地。将文件重命名为“___nuget.config”修复了 TeamCity 并破坏了 Azure,在我们搬出 TeamCity 之前,我将不得不在不同的分支上工作。
  • 您的意思是您的问题有解决方案吗?如果是这种情况,您可以添加回复和Accept it as an Answer,这可能对阅读此主题的其他社区成员有所帮助。

标签: nuget azure-pipelines-build-task azure-pipelines-yaml


【解决方案1】:

您可以查看Replace Tokens 扩展名,看看它是否对您有帮助。它可以在管道期间将文件中的标记替换为变量值。

【讨论】:

    【解决方案2】:

    我不会将其称为解决方案,因为我无法将 nuget.config 信息从文件中移到命令行中,我将删除该文件以使 Team City 能够工作,并在运行 Azure 管道时将其放回原处.谢谢。

    【讨论】:

    • 您可以在您的 nuget.config 中添加此 &lt;disabledPackageSources&gt; &lt;add key="FeedName" value="true" /&gt; &lt;/disabledPackageSources&gt; 以禁用此提要,或者您可以将其从您的存储库中删除。
    猜你喜欢
    • 2021-08-12
    • 2017-06-24
    • 2012-01-05
    • 2020-09-28
    • 1970-01-01
    • 1970-01-01
    • 2015-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多