问题
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:
- They are not located in the solution folder for each of our team projects (ie. /Solution/packages/*)
- 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.
回答1:
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
来源:https://stackoverflow.com/questions/34318069/setting-an-environment-variable-in-a-nuget-config-file