0
votes

In Azure DevOps I have my company nuget repository. I have created some new nuget packages and I included them in my projects. Locally the projects are working fine.

When I run the dotnet build on DevOps there is error because there is an unauthorize access to the nuget repository.

enter image description here

[error]C:\Program Files\dotnet\sdk\3.1.202\NuGet.targets(124,5): Error : Unable to load the service index for source https://vs.pkgs.visualstudio.com/Vs/_packaging/vs.com/nuget/v3/index.json.

Response status code does not indicate success: 401 (Unauthorized).

C:\Program Files\dotnet\sdk\3.1.202\NuGet.targets(124,5): error : Unable to load the service index for source https://vs.pkgs.visualstudio.com/Vs/_packaging/vs.com/nuget/v3/index.json. [d:\a\1\s\Payments\Payments.csproj]

C:\Program Files\dotnet\sdk\3.1.202\NuGet.targets(124,5): error : Response status code does not indicate success: 401 (Unauthorized). [d:\a\1\s\PiP.Payments.Stripe\PiP.Payments.csproj]

Build FAILED.

C:\Program Files\dotnet\sdk\3.1.202\NuGet.targets(124,5): error : Unable to load the service index for source https://vs.pkgs.visualstudio.com/Vs/_packaging/vs.com/nuget/v3/index.json. [d:\a\1\s\PiP.Payments.Stripe\PiP.Payments.csproj]

C:\Program Files\dotnet\sdk\3.1.202\NuGet.targets(124,5): error : Response status code does not indicate success: 401 (Unauthorized).

1
Could you please include your build yaml file or build configuration excluding secrets?John Verbiest
Did you have a try with below solution? How did it go?Levi Lu-MSFT

1 Answers

6
votes

We have had this error several times before. We were always able to fix it with an extra dotnet restore command before the dotnet build command.

There is a small hint in the documentation here: https://docs.microsoft.com/en-us/azure/devops/artifacts/nuget/dotnet-exe?view=azure-devops#on-build-machines-and-in-non-interactive-scenarios

In Azure Pipelines, use the .NET Core step's restore command, which automatically handles authentication to Azure Artifacts feeds. Otherwise, use the Azure Artifacts Credential Provider and pass in credentials using the VSS_NUGET_EXTERNAL_FEED_ENDPOINTS environment variable.

Here is an example yaml:

    - task: DotNetCoreCLI@2
      displayName: 'Restore Packages'
      inputs:
        command: restore
        projects: 'MyCsproj.csproj'
        vstsFeed: 'voxspan'

    - task: DotNetCoreCLI@2
      displayName: 'Build'
      inputs:
        command: build
        projects: 'MyCsproj.csproj'