Set the global credential provider #1018 #1021
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix for #1018 that sets the global credential provider. This allows the NuGet HttpClient to use the credentials stored in NuGet.Config .
I tested this by editing my
%APPDATA%\NuGet\NuGet.Configfile to usepackageSourceCredentialsfor our myget feeds, specifically our nuget mirror. This file has Username and Password credentials for some of the MyGet feeds and nuget.org is disabled using:I produced two builds using
build.cmd, one from before the change and one from after and watched what they did using Fiddler. The build before the change would try the various feeds once and get a 401 response for each then just give up. The build after the change would retry with credentials following the 401 response getting 404s for most and a 200 for the package on the mirror feed. More importantly the build with the fix actually installed some packages too!Regarding the approach, to my knowledge setting this global property is the only way to configure the NuGet HttpClient to use these credentials. It kind of makes me wonder if this should be fixed in NuGet.Core instead of here in script CS but I guess that is up to you all and those working on NuGet v2.
The location for this one line was chosen because of the proximity to the
PackageSourceProviderinstance. I would like to see this code inInitializebut I don't think setting it multiple times should hurt and I also don't see theGetRepositorySourcesmethod called anywhere except forInitialize.Some things to note:
build.cmd.