Animal Style
Animal Style

Reputation: 709

dotnet new --install is looking at wrong NuGet server

Running:

dotnet new --install Microsoft.AspNetCore.SpaTemplates::*

Generates the below error:

C:\Program Files (x86)\dotnet\sdk\1.0.4\Nuget.targets(97,5): error : Unable to laod the service index for source https://MYNugetFeed.pkgs.visualstudio.com/_packaging/Project/nuget/v3/index.json. \r [C:\Users\me\.templateengine\dotnetcli\v1.0.4\scratch\restore.csproj]

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

So my questions is why is it looking at that NuGet feed and not the standard (assuming that's where these templates are) and how do I change the configuration for dotnet cli? I know this is environment related in some way.

Upvotes: 9

Views: 5042

Answers (3)

Brian MacKay
Brian MacKay

Reputation: 32019

Cause

When you set up NuGet servers in Visual Studio (and perhaps other tools), they are saved on a per-user basis in NuGet.config. Dotnet new -install tries to make use of them. Unfortunately, one of my nuget servers (Telerik) requires authentication, and it failed so hard that it stopped all the other sources from even being tried.

Solution

On both Windows 10 and 11, you can find NuGet.Config here:

Go to C:\Users\[User Name]\AppData\Roaming\NuGet\NuGet.Config

Under <packageSources>, there will be a list of servers, like this:

<packageSources>
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
    <add key="REDACTED" value="http://REDACTED:8080/guestAuth/app/nuget/v1/FeedService.svc/" />
    <add key="REDACTED" value="http://REDACTED/nuget" />
    <add key="Telerik (Kendo)" value="https://nuget.telerik.com/nuget" />
</packageSources>

To make this work, I reduced that down to the core nuget.org server:

<packageSources>
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>

...And then template installation started working.

Upvotes: 14

TwainJ
TwainJ

Reputation: 1197

I had, presumably, the same problem Brian MacKay encountered with Telerik. However, I am actively working a project that needed the Telerik source, so I wasn't keen to remove everything from my Nuget.Config

However, by specifying the specific nuget source in the command, I was able to install the desired templates - in my case IdentityServer4 templates. So this command worked:

dotnet new -i IdentityServer4.Templates --nuget-source https://api.nuget.org/v3/index.json

Assuming that the OP is correct and the templates mentioned are in the standard Nuget registry, I imagine a similar call would work there.

Upvotes: 6

Joe Mahoney
Joe Mahoney

Reputation: 903

It sounds like your computer has a global nuget configuration that points to that feed. You can change that behaviour for a specific directory and it's children by creating a new nuget.config file.

You can find out how the local files override global ones on the Configuring Nuget Behavior page of the Nuget documentation.

Upvotes: 6

Related Questions