我们可以用命令参数替换 nuget.config 文件吗?

Can we replace nuget.config file with command parameters?

我正在 Windows 自托管代理上开发通往 运行 的 Azure 管道。 我们配置了一个带有上游连接到 Nuget 的 Artefact 提要。 由于我们在防火墙后面,这似乎是连接到 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 中以前的管道!! 为了在处理新文件时保留旧文件 运行ning,我正在寻找一种方法将信息从 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).

感谢您的帮助

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

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