Skip to content

Conversation

@aarondandy
Copy link
Contributor

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.Config file to use packageSourceCredentials for 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:

  <disabledPackageSources>
    <add key="https://www.nuget.org/api/v2/" value="true" />
  </disabledPackageSources>

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 PackageSourceProvider instance. I would like to see this code in Initialize but I don't think setting it multiple times should hurt and I also don't see the GetRepositorySources method called anywhere except for Initialize.

Some things to note:

  • No tests were created for this change. I really don't know a practical way to create a test for this change.
  • The code that was edited does not appear to have any existing coverage (using NCrunch).
  • I have no test failures before or after this change using build.cmd.

@adamralph adamralph changed the title Fix for #1018 that sets the global credential provider Set the global credential provider #1018 Jul 29, 2015
@aarondandy
Copy link
Contributor Author

This may be an alternative way to solve this problem in the future if scriptcs can allow configuration for it: http://docs.nuget.org/Consume/Credential-Providers

@glennblock
Copy link
Contributor

@scriptcs/core thoughts?

@glennblock
Copy link
Contributor

This looks reasonable to me as long as it does not affect existing users that are not requiring credentials.

@glennblock glennblock merged commit ffcd2ff into scriptcs:dev Sep 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants