Forum Discussion
Dotnet tool install 401 Unauthorized
The error you're encountering is due to the NuGet configuration pointing to a private Azure Artifacts feed, which requires authentication. To resolve this, you can provide the necessary credentials to access the private feed. Here are a few methods to pass the credentials for the dotnet tool install command:
Method 1: Use --configfile Option
You can specify a NuGet.config file that does not contain the private feed configuration by using the --configfile option. Create a separate NuGet.config file that only includes the default NuGet sources.
Create a new NuGet.config file (e.g., NuGetPublic.config) with the following content:
xmlCopy code<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <clear /> <add key="nuget.org" value="https://api.nuget.org/v3/index.json" /> </packageSources> </configuration>Run the dotnet tool install command with the --configfile option:
shCopy codedotnet tool install --global dotnet-reportgenerator-globaltool --version 4.0.15 --configfile NuGetPublic.config
Method 2: Temporarily Remove the Private Feed
If modifying the NuGet.config is not feasible, you can temporarily remove the private feed from the configuration file during the tool installation and add it back afterward.
Backup your existing NuGet.config file:
shCopy codecp path/to/nuget.config path/to/nuget.config.bakRemove the private feed configuration from the NuGet.config.
Run the dotnet tool install command:
shCopy codedotnet tool install --global dotnet-reportgenerator-globaltool --version 4.0.15Restore the original NuGet.config:
shCopy codemv path/to/nuget.config.bak path/to/nuget.config
Method 3: Set up Environment Variables for Credentials
You can set up environment variables for the NuGet credentials required for accessing the private feed. This is useful if you have the credentials stored in a secure manner and need to provide them dynamically.
Export the environment variables with the necessary credentials:
shCopy codeexport NUGET_USERNAME=your-username export NUGET_PASSWORD=your-passwordRun the dotnet tool install command:
shCopy codedotnet tool install --global dotnet-reportgenerator-globaltool --version 4.0.15
For more information, you can refer to the following resources:
By following these methods, you should be able to install the tool without encountering the 401 Unauthorized error.
For backlinks, mentioned the websites: