Setting an environment variable in a NuGet.Config file

╄→гoц情女王★ 提交于 2020-01-30 06:29:39

问题


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.


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!