Forum Discussion

smithjohn039's avatar
smithjohn039
Copper Contributor
Oct 04, 2022

Dotnet tool install 401 Unauthorized

I'm trying to install the "dotnet-reportgenerator-globaltool" tool via .Net Core custom task.

 

Custom Command: tool

Arguments: install --global dotnet-reportgenerator-globaltool --version 4.0https://thecapcut.com/15

 

Problem: When executing from a directory that contains a nuget.config pointing to a private azure artifacts, I get an error like the following. I don't want to use my feed or need tohttps://thecapcut.com/ but because the nuget.config exists I have no choice. Is there a way I can pass credentials to this command? There is no directory that doesn't inherit the nuget.config :sad:

 

[command]"C:\Program Files\dotnet\dotnet.exe" tool install --global dotnet-reportgenerator-globaltool --version 4.0.15
C:\Program Files\dotnet\sdk\2.2.104\NuGet.targets(114,5): error : Unable to load the service index for source https://pkgs.dev.azure.com/bstglobal/_packaging/BSTWEB/nuget/v3/index.json. [C:\Users\VssAdministrator\AppData\Local\Temp\rkrgqk3i.dkp\restore.csproj]
C:\Program Files\dotnet\sdk\2.2.104\NuGet.targets(114,5): error : Response status code does not indicate success: 401 (Unauthorized). [C:\Users\VssAdministrator\AppData\Local\Temp\rkrgqk3i.dkp\restore.csproj]
The tool package could not be restored.

 

 

9 Replies

  • aadilkhan3007's avatar
    aadilkhan3007
    Copper Contributor

    Hi, You can use https://www.letsreduce.com  to make image small for upload related to your question.

  • evaelfie5091's avatar
    evaelfie5091
    Copper Contributor

    Temporarily Disable nuget.config:

    Pros: Simple and effective for quick installations.
    Cons: Might introduce problems if other tasks rely on the private feed.
    Steps:
    Back up your original nuget.config file.
    Rename or move the file to a temporary location outside the current directory.
    Run dotnet tool install --global dotnet-reportgenerator-globaltool --version 4.0.15.
    After successful installation, restore the original nuget.config file.
    Use a Separate Directory without nuget.config:

    Pros: Keeps your configuration clean and avoids unintended interactions.
    Cons: Requires creating a new directory of https://qatarvisastatuscheck.qa/, and potentially changing build paths.
    Steps:
    Create a new directory that doesn't have a nuget.config file in its parent hierarchy.
    Navigate to the new directory.
    Run dotnet tool install --global dotnet-reportgenerator-globaltool --version 4.0.15.
    Advanced Solution (if necessary):

    Use NuGet.exe Command Line with API Key:

    Pros: Provides more control and can be integrated into scripts.
    Cons: More complex setup, requires obtaining an Azure Artifacts API key.
    Steps:
    Obtain an Azure Artifacts API Key:

    Navigate to your Azure Artifacts project in Azure DevOps.
    Go to Packages > Settings.
    Under API, generate a personal access token with the Packages scope.
    Use NuGet.exe:

    Open a command prompt or terminal.
    Navigate to the directory containing NuGet.exe (usually C:\Program Files\dotnet\sdk\<version>\NuGet.exe).
    Run the following command, replacing placeholders with your actual values:
    NuGet.exe install -Source https://pkgs.dev.azure.com/<organization>/<project>/_packaging/<feedName>/nuget/v3/ -ApiKey <your_api_key> -PackageId dotnet-reportgenerator-globaltool -Version 4.0.15 -GlobalForce

    • shabirqureshi1's avatar
      shabirqureshi1
      Copper Contributor

      Hello Everyone, 

                                  I have a tool-based (niche blogging) https://genorandom.com/ named GenoRandom. I'm facing some bugs on the front end. Is there any expert who can review it and suggest a solution?

      I shall be very thankful.

      Best Regards.

  • sshhiivva0's avatar
    sshhiivva0
    Copper Contributor

     

    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.

    1. Create a new NuGet.config file (e.g., NuGetPublic.config) with the following content:

      xml
      Copy 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>
    2. Run the dotnet tool install command with the --configfile option:

      sh
      Copy code
      dotnet 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.

    1. Backup your existing NuGet.config file:

      sh
      Copy code
      cp path/to/nuget.config path/to/nuget.config.bak
    2. Remove the private feed configuration from the NuGet.config.

    3. Run the dotnet tool install command:

      sh
      Copy code
      dotnet tool install --global dotnet-reportgenerator-globaltool --version 4.0.15
    4. Restore the original NuGet.config:

      sh
      Copy code
      mv 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.

    1. Export the environment variables with the necessary credentials:

      sh
      Copy code
      export NUGET_USERNAME=your-username export NUGET_PASSWORD=your-password
    2. Run the dotnet tool install command:

      sh
      Copy code
      dotnet tool install --global dotnet-reportgenerator-globaltool --version 4.0.15

    For more information, you can refer to the following resources:

    • https://docs.microsoft.com/en-us/nuget/consume-packages/configuring-nuget-behavior
    • https://github.com/microsoft/artifacts-credprovider

    By following these methods, you should be able to install the tool without encountering the 401 Unauthorized error.

    For backlinks, mentioned the websites:

    • https://compresstools.com
    • https://resizeimagez.com

    smithjohn039 

  • smithjohn039 

    It sounds like you're running into a common issue with private NuGet feeds. One way to address this is by temporarily disabling the nuget.config file that points to your private feed, if that's feasible. Alternatively, you can try specifying a different configuration file or explicitly passing the credentials using a NuGet CLI command before running your custom task. For creating professional email signatures, you might find https://creadordefirmas.com/ helpful. I hope this helps!

  • jackson32's avatar
    jackson32
    Copper Contributor

    mee to trying to install the "dotnet-reportgenerator-globaltool" tool via .Net Core custom task.

     

    Custom Command: tool

    Arguments: install --global dotnet-reportgenerator-globaltool --version 4.0https://compresskaru.com/resize-image-to-3000x3000/15

     

    Problem: When executing from a directory that contains a nuget

  • LanHuang's avatar
    LanHuang
    Iron Contributor

    Hi smithjohn039,

    Thanks for posting your issue here.

    However this platform is used for how-to discussions and sharing best practices for building any app with .NET.Since your issue is a technical question, welcome to post it in Microsoft Q&A forum, the support team and communities on Microsoft Q&A will help you for any technical questions.
    Besides, it will be appreciated if you can share it here once you post this technical question Microsoft Q&A.
    Best Regards,
    Lan Huang

    • smithjohn039's avatar
      smithjohn039
      Copper Contributor

      LanHuang  

      Issue Resolved, Thanks for the proper guidance


      LanHuang wrote:

      Hi smithjohn039,

      Thanks for posting your issue here.

      However this platform is used for how-to discussions and sharing best practices for building any app with .NET.Since your issue is a technical question, welcome to post it in https://docs.microsoft.com/en-us/answers/products/dotnethttps://jeepmarketing.com/ forum, the support team and communities on Microsoft Q&A will help you for any technical questions.
      Besides, it will be appreciated if you can share it here once you post this technical question Microsoft Q&A.
      Best Regards,
      Lan Huang


       

      • nestorcarbonell's avatar
        nestorcarbonell
        Copper Contributor

        How did you solve it

         

        Issue Resolved, Thanks for the proper guidance

        @LanHuang wrote:

        Hi @smithjohn039,

        Thanks for posting your issue here.

        However this platform is used for how-to discussions and sharing best practices for building any app with .NET.Since your issue is a technical question, welcome to post it in https://docs.microsoft.com/en-us/answers/products/dotnethttps://jeepmarketing.com/ forumhttp://wishcodes.com the support team and communities on Microsoft Q&A will help you for any technical questions.
        Besides, if you can share it here is another technical question; Is there a user-friendly Windows application available for controlling ceiling fans? Similar to the PC fan control software I use, I'm hoping to find a convenient solution that allows office workers like myself to adjust fan speed for an instant http://wishcodes.com/ from my desktop, eliminating the need to get up and reach out to the wall outlet's physical controls." Microsoft Q&A.

        Best Regards,
        Lan Huang

Resources