在 NuGet.Config 文件中设置环境变量 [英] Setting an environment variable in a NuGet.Config file
问题描述
我想将 NuGet.config
文件的 repositoryPath
变量设置为相对于当前用户机器的位置.目标是拥有一个放置所有 NuGet 包的位置,以便:
- 它们不在我们每个团队项目的解决方案文件夹中(即./Solution/packages/*)
- 它们在许多项目中共享,因此只需要在机器上安装该软件包的一个副本.
理想情况下,我想使用带有环境变量的路径,例如 %APPDATA%
,但是 NuGet 包管理器不支持此操作.
我的配置文件如下所示:
<add key="repositoryPath" value="C:\External\NuGetPackages"/><add key="DefaultPushSource" value="\\SourceCode\NuGetPackages\"/></config>
理想情况下,我希望 repositoryPath 像这样工作:
我尝试过的事情:
$(APPDATA)$APPDATA$Env:APPDATA
前两个只会导致这些名称与 NuGet.config 文件位于同一位置的目录.
这已作为 NuGet v3.4+ 中的一项功能添加
现在可以使用标准语法在 Windows 中添加变量,例如:
<预><代码><配置><配置><add key="repositoryPath" value="%HOME%\NuGetRepository"/></config></配置>参见 https://docs.nuget.org/consume/nuget-config-file#environment-variables-in-configuration
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.
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
这篇关于在 NuGet.Config 文件中设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!