nuget - 恢复包时 dotnet build 命令失败

标签 nuget azure-devops nuget-package-restore

我有一个在本地构建良好的项目,但在 VSTS 中构建它在 dotnet build 命令中失败。这个错误对我来说看起来很奇怪,因为我不知道为什么构建命令会再次尝试恢复包。错误如下所示:

2018-07-09T11:06:48.2541705Z Retrying 'FindPackagesByIdAsync' for source 'https://mycompany.pkgs.visualstudio.com/_packaging/5b9fd539-d653-4771-aa3c-6544d73b1234/nuget/v3/flat2/system.data.sqlclient/index.json'. 2018-07-09T11:06:48.2562315Z Response status code does not indicate success: 401 (Unauthorized).

在构建步骤之前,我有一个成功完成的 dotnet 还原步骤。还原步骤使用 NuGet.config 文件,其中包含 VSTS 中的私有(private)提要,但 URL 看起来与错误中的不相似。这里的文件只是为了清楚起见。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="MyCompany.NuGet.Internal" value="https://MyCompany.pkgs.visualstudio.com/_packaging/MyCompany.NuGet.Internal/nuget/v3/index.json" />
    <add key="MyCompany.NuGet.ThirdParty" value="https://MyCompany.pkgs.visualstudio.com/_packaging/MyCompany.Nuget.ThirdParty/nuget/v3/index.json" />
  </packageSources>
</configuration>

这可能是什么问题? dotnet 构建步骤是否完全忽略 NuGet.config 文件并尝试项目中的提要?我不知道该供稿 URL 是如何生成的。

最佳答案

我能够通过将 --no-restore 参数传递给 dotnet build 命令来解决问题。

我刚刚读了this article here并想试一试,结果成功了。

With .NET Core 1.x SDK, you needed to explicitly run the dotnet restore before running dotnet build. Starting with .NET Core 2.0 SDK, dotnet restore runs implicitly when you run dotnet build. If you want to disable implicit restore when running the build command, you can pass the --no-restore option

看起来 VSTS 中的 dotnet build 不关心 NuGet.config 文件,并尝试在没有它的情况下进行恢复。

关于nuget - 恢复包时 dotnet build 命令失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51244716/

相关文章:

c# - NuGet - 以编程方式安装包(多个来源)

.net - 无法在 travis 上从命令行让 nuget 工作

android - 通过 Android Studio 将现有的 Android 项目添加到 VSTS

c# - 在 VSTS 中运行 xunit.net 测试

c# - GitHub Actions 工作流程 - 已发布的 Nuget 包始终标记为预发布

.net - nuget 提要和促销

sql-server - 如何在 Azure DevOps 管道中将变量注入(inject) SQL 脚本?

c# - 从复制的 package.config 添加引用

c# - "Reference the package directly from the project to resolve this issue."

visual-studio-2015 - Visual Studio dotnet 命令行工具版本错误