dotnet build 命令在还原包时失败 [英] dotnet build command fails while restoring packages

查看:53
本文介绍了dotnet build 命令在还原包时失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a project that's building fine locally but the build in VSTS it fails in dotnet build command. The error looks very strange to me because I have no idea why a build command would try to restore packages again. Here's what the error looks like:

2018-07-09T11:06:48.2541705Z 重试FindPackagesByIdAsync"来源'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 响应状态码不指示成功:401(未经授权).

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 restore 步骤.还原步骤使用 NuGet.config 文件,其中包含 VSTS 中的私有源,但 URL 看起来与错误中的 URL 不同.这里的文件只是为了清楚起见.

Prior to build step, I have a dotnet restore step which is completed successfully. Restore step uses a NuGet.config file which includes private feeds in VSTS but the URLs do not look similar to the one in the error. Here's the file just to make it clear.

<?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 是如何生成的.

What could be the problem here? Is dotnet build step ignoring the NuGet.config file completely and trying the feeds in the project? I have no idea how that feed URL is generated.

推荐答案

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

I was able to resolve the issue by passing --no-restore argument to dotnet build command.

我刚刚阅读了这篇文章在这里并想试一试,它奏效了.

I just read this article here and wanted to give it a shot and it worked.

使用 .NET Core 1.x SDK,您需要显式运行 dotnet在运行 dotnet build 之前恢复.从 .NET Core 2.0 SDK 开始,运行 dotnet build 时,dotnet restore 会隐式运行.如果你想要在运行构建命令时禁用隐式还原,您可以传递 --no-restore 选项

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 文件并尝试在没有它的情况下进行还原.

It looks like dotnet build in VSTS does not care about the NuGet.config file and tries to do a restore without it.

这篇关于dotnet build 命令在还原包时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆