问题
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 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).
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>
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.
回答1:
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.
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
It looks like dotnet build
in VSTS does not care about the NuGet.config file and tries to do a restore without it.
来源:https://stackoverflow.com/questions/51244716/dotnet-build-command-fails-while-restoring-packages