2

I have a situation where I want to set the repositoryPath variable of the NuGet.config file to a location relative to the current user's machine. The goal is to have a location where all of the NuGet packages get placed, so that:

  1. They are not located in the solution folder for each of our team projects (ie. /Solution/packages/*)
  2. They are shared across many projects, so that only one copy of that package needs to be installed on the machine.

Ideally, I would like to use a path with an environment variable, such as %APPDATA%, however the NuGet Package Manager doesn't work with this.

My config file looks something like this:

  <config>
    <add key="repositoryPath" value="C:\External\NuGetPackages" />
    <add key="DefaultPushSource" value="\\SourceCode\NuGetPackages\" />
  </config>

Where ideally I would like the repositoryPath to work like this:

<add key="repositoryPath" value="%APPDATA%\External\NuGetPackages" />

Things I have tried:

$(APPDATA)
$APPDATA
$Env:APPDATA

The first two of these just result in directories with those names being placed in the same location as the NuGet.config file.

mikeyq6
  • 1,138
  • 13
  • 27
  • 1
    This is not supported. There is no environment variable expansion done by NuGet when it reads the NuGet.Config file. You should file a feature request at https://github.com/nuget/home – Matt Ward Dec 17 '15 at 10:21
  • Thanks. I submitted a feature request. – mikeyq6 Dec 18 '15 at 14:49
  • 1
    Update: This has been added as a feature in NuGet v3.4+, See https://docs.nuget.org/consume/nuget-config-file#environment-variables-in-configuration – mikeyq6 Sep 12 '16 at 09:31

1 Answers1

2

This has been added as a feature in NuGet v3.4+

Variables can now be added in Windows using the standard syntax, eg:

<configuration>
    <config>
        <add key="repositoryPath" value="%HOME%\NuGetRepository" />
    </config>
</configuration>

See https://docs.nuget.org/consume/nuget-config-file#environment-variables-in-configuration

mikeyq6
  • 1,138
  • 13
  • 27