7

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.

Animal Style
  • 689
  • 2
  • 10
  • 31

3 Answers3

11

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.

Brian MacKay
  • 31,133
  • 17
  • 86
  • 125
  • While this does solve the original problem, it creates a new one: You no longer have access to Telerik's Nuget server. To solve that problem, add a NuGet.Config file to the Solution folder for the project that uses Telerik packages. The new config file only needs the missing Telerik key, since the package manager combines all available configs when it is run. – Doug Aug 21 '20 at 15:55
6

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.

Joe Mahoney
  • 903
  • 6
  • 14
  • 4
    Thanks this led me to AppData\Roaming\NuGet\NuGet.Config file. I had to remove all non nuget sources to get it to work :/ – Animal Style Jun 12 '17 at 22:06
6

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.

TwainJ
  • 1,187
  • 1
  • 13
  • 26
  • 1
    See my comment on Brian MacKay's answer. You can add a project-specific NuGet.Config file wherever you need access to Telerik's feed. – Doug Aug 21 '20 at 15:56
  • Thanks @Doug! interestingly, I discovered that too with an unrelated Nuget challenge I had. Now that I know that, I realize that that is what Joe's answer is getting at, although, I think at the time, I assumed he was just talking about changing the global Nuget config. – TwainJ Aug 27 '20 at 22:26
  • Oh, I think you're right! I missed that the first time through as well. – Doug Aug 31 '20 at 15:52