2

Our project references packages in our private artifact source in Azure DevOps. When building the project in Azure DevOps the dotnet restore completes fine but dotnet build also tries to restore the packages and fails with

Unable to load the service index for source https://myazdevops.pkgs.visualstudio.com/_packaging/OurPackages/nuget/v3/index.json

The work around is adding --no-restore to both the dotnet build and dotnet publish tasks.

Is there some way to have the build and publish start working without there parameters?

akiller
  • 2,462
  • 22
  • 30
Mathias Rönnlund
  • 4,078
  • 7
  • 43
  • 96

3 Answers3

1

I had similar issues with our internal NuGet feed. I resolved it by adding nuget.config file in repository that contains both NuGet.org and our internal NuGet repository.

<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
    <add key="internal" value="URL_TO_INTERNAL_FEED" />
  </packageSources>
</configuration>

Then just specify in your Restore step Path to NuGet.config to this file.

Hope it will help.

Nick43
  • 71
  • 2
  • 2
    We actually did this, but then we get 401 Access denied. Seems like dotnet restore is the only command that can do authentication against the nuget repo. – Mathias Rönnlund Sep 09 '19 at 14:16
  • Now I checked, I also added --no-restore to Build step. I also added --no-build to Publish step since it was already built. If you can live with it... – Nick43 Sep 09 '19 at 14:28
1

I think your workaround is the solution, in the official docs written:

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.

You can't disable this behavior unless you add --no-restore.

See also this question & answer.

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
1

We have opened the source code in Github, you can refer to the code of dotnet build command. This is a compile command, so we did not make script in the task to set the authinfo additionally. Also, as you know, the dotnet restore runs implicitly while the dotnet build running only after .net core 2.0. In fact, this dotnet restore which runs implicitly is not a necessary part if you have been run dotnet restore before the dotnet build. That's why we offered the workaround - add --no-restore - to avoid this implicitly command.

This is a very convenient method which can make your compile process very concise. But if you still don't want this argument, you need do another configuration job to authorized with credential.

Configure the Azure Artifacts Credential Provider, then pass in the credentials with the VSS_NUGET_EXTERNAL_FEED_ENDPOINTS environment variable. VSS_NUGET_EXTERNAL_FEED_ENDPOINTS contain the endpoint credentials for any feed that you need to authenticate against with a JSON Format.

Mengdi Liang
  • 17,577
  • 2
  • 28
  • 35