4

First I add my package source (test).

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="test" value="https://mytestpackagesource" />
  </packageSources>
</configuration>

When I run dotnet restore I get a 401 (Unauthorized), which is expected. So I add credentials.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="test" value="https://mytestpackagesource" />
  </packageSources>
  <packageSourceCredentials>
    <test>
        <add key="Username" value="apparently this can be anything when you use a token?" />
        <add key="ClearTextPassword" value="my personal access token" />
    </test>
  </packageSourceCredentials>
</configuration>

And this works. But if I change the token to something invalid or even remove the packageSourceCredentials element completely it still works, which makes me believe my token got stored somewhere else. So my question is where did it get stored and how do I update it?

cassonchris
  • 81
  • 1
  • 7
  • 1
    Try running `nuget locals http-cache -clear` and see if that solves the problem. Visual Studio on Windows also have some caching that lasts I think 30 minutes. – Matt Ward Feb 25 '20 at 20:27
  • Visual Studio doesn't detect when a nuget.config is modified while a solution is open. If you do modify a nuget.config, you should close the solution and open it again. But using the dotnet cli should reload the config every execution. Is it possible you have the correct credentials in multiple config files, and when you tried changing it to something wrong, you changed it in a file that isn't used? If you restore with normal verbosity (the dotnet cli defaults to minimal verbosity), NuGet prints a list of all the nuget.config files read. – zivkan Feb 25 '20 at 21:02

1 Answers1

1

As @matt-ward suggested. The following works for me to re-introduce invalid credentials error

nuget locals http-cache -clear
Andriod
  • 1,239
  • 12
  • 18