Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for envvars in NuGet.config - improve docs for xplat behavior #8662

Closed
infin8x opened this issue Oct 4, 2019 · 11 comments
Closed

support for envvars in NuGet.config - improve docs for xplat behavior #8662

infin8x opened this issue Oct 4, 2019 · 11 comments

Comments

@infin8x
Copy link

infin8x commented Oct 4, 2019

Details about Problem

NuGet product used: dotnet on Mac

dotnet.exe --version (if appropriate): 2.2.104

OS version (i.e. win10 v1607 (14393.321)): macOS Mojave 10.14.6

Worked before? If so, with which NuGet version: [Was No, @rrelyea added comment with link to docs. Perhaps this is a dotnet.exe bug only?]

Detailed repro steps so we can see the same problem

  1. Set up NuGet.configs and add a valid token to your environment like so:
    image

  2. Attempt to run dotnet restore:
    image

  3. Move token to file directly (to prove that it's a valid token and not a server-side issue):
    image

Note: I know there is a token in these screenshots. I revoked it before publishing.

Other suggested things

Verbose Logs

log.txt

Sample Project

You can git clone https://github.com/infin8x/starter-packages and use the nuget-bacon package.

@infin8x
Copy link
Author

infin8x commented Oct 4, 2019

@anangaur sorry for the long delay, but here's the issue I promised to file.

@infin8x infin8x changed the title dotnet doesn't support enviers in NuGet.config dotnet doesn't support envvars in NuGet.config Oct 4, 2019
@rrelyea rrelyea changed the title dotnet doesn't support envvars in NuGet.config add support envvars in NuGet.config Oct 4, 2019
@rrelyea rrelyea changed the title add support envvars in NuGet.config add support for envvars in NuGet.config Oct 4, 2019
@rrelyea
Copy link
Contributor

rrelyea commented Oct 4, 2019

Looks like I evolved the title badly. We do support envvars in nuget.config, and it should work on mac/linux too.
https://docs.microsoft.com/en-us/nuget/reference/nuget-config-file#using-environment-variables

@rrelyea rrelyea changed the title add support for envvars in NuGet.config support for envvars in NuGet.config - should work in dotnet.exe too Oct 4, 2019
@rrelyea
Copy link
Contributor

rrelyea commented Oct 4, 2019

This works fine with dotnet.exe 3.0 on windows:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="nuget" value="%myfeed%" />
    <add key="local" value="%localfeed%" />
  </packageSources>
</configuration>

@rrelyea
Copy link
Contributor

rrelyea commented Oct 4, 2019

@infin8x - can you try %NUGET_AUTH_TOKEN% instead of $NUGET_AUTH_TOKEN.
I think we call ExpandEnvironmentVariables, which doesn't document different character behavior on different platforms. Also, trying netcore 3.0 might be best...so we can test our latest behavior.

@infin8x
Copy link
Author

infin8x commented Oct 7, 2019

No dice, that also fails, even after I install netcore 3.0.

Simplest repro of this:

  1. Clone the repo I referenced above, on a Mac.
  2. Make .nuget\nuget\nuget.config like the example below.
  3. Add your token as an envvar.
  4. Run dotnet restore.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
<packageSourceCredentials>
    <GPR>
      <add key="username" value="infin8x" />
      <add key="cleartextpassword" value="%NUGET_AUTH_TOKEN%" />
    </GPR>
  </packageSourceCredentials>
</configuration>

@infin8x
Copy link
Author

infin8x commented Oct 7, 2019

But, I agree that this works on Windows, I think this is a Mac(/Linux)-only issue.

@rrelyea rrelyea self-assigned this Oct 10, 2019
@rrelyea rrelyea added this to the Backlog milestone Oct 10, 2019
@rrelyea
Copy link
Contributor

rrelyea commented Oct 14, 2019

Looks like %foo% works fine on dotnet.exe 3.0 on linux (ubuntu 18.4)
I tested, with success, against a private azure artifacts feed (devdiv/vs)
Then I tested against a GPR feed ... w/o success.

My guess is that this is GPR implementation related.
If you can help me get GPR access...i'll dig into this more next week.
However, i think you could try both scenarios i mention...and see the difference in GPR implemetantion of communication with nuget client.

@rrelyea
Copy link
Contributor

rrelyea commented Oct 21, 2019

@infin8x - see my last comment.

@rrelyea rrelyea modified the milestones: Backlog, 5.4 Oct 28, 2019
@rrelyea
Copy link
Contributor

rrelyea commented Oct 28, 2019

work remaining here is to make sure we improve our docs.

@rrelyea rrelyea changed the title support for envvars in NuGet.config - should work in dotnet.exe too support for envvars in NuGet.config - improve docs for xplat behavior Oct 28, 2019
@infin8x
Copy link
Author

infin8x commented Oct 28, 2019

Sorry for the delay here, I think someone from the GPR team is digging in more to what's going on here. But, glad to know the envvar works. Looking forward to the docs improvement.

@rrelyea
Copy link
Contributor

rrelyea commented Jul 20, 2020

there is a modified section about env vars in config files here: https://docs.microsoft.com/en-us/nuget/reference/nuget-config-file#using-environment-variables
It properly covers x-plat env var techniques.

also https://docs.microsoft.com/en-us/nuget/reference/nuget-config-file#packagesourcecredentials has been updated with a sample.

@rrelyea rrelyea closed this as completed Jul 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants