摘要:我们有一个脚本,可以从我们的解决方案存储库中的命令行运行 nuget.exe。我们如何将 NuGet 配置为仅使用特定的包源(而不是机器范围或用户配置中列出的任何内容)?
从 NuGet 文档中,可以阅读以下有关链接多个配置文件的内容:
NuGet 首先从默认位置加载 NuGet.config,然后从当前驱动器的根目录开始加载任何名为 NuGet.config 的文件,并以当前目录结束。(...) 当
<clear />
给定节点存在时,将忽略该节点先前定义的配置项。
在我们存储库的根目录中,我们添加了以下 NuGet.Config 文件,以确保我们只从自己的内部 NuGet 存储库中获取 NuGet 包:
<!-- C:\repository_root_path\NuGet.Config -->
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
</packageRestore>
<packageSources>
<clear /> <!-- ensure only the sources defined below are used -->
<add key="Internal package source" value="\\network_fileshare\nuget_packages\" />
</packageSources>
<disabledPackageSources />
<activePackageSource>
<add key="Internal package source" value="\\network_fileshare\nuget_packages\" />
</activePackageSource>
</configuration>
我们现在遇到的问题是,这会根据我们运行的 NuGet.exe 版本产生不同的结果。为了调试,我下载了三个不同版本的 NuGet.exe,并将它们全部放在我们解决方案的 .nuget 文件夹中。结果如下:
C:\repository_root_path>Source\.nuget\nuget_2.5.40416.exe sources
Registered Sources:
1. Internal package source [Enabled]
\\network_fileshare\nuget_packages\
C:\repository_root_path>Source\.nuget\NuGet_2.6.40619.exe sources
Registered Sources:
1. NuGet official package source [Enabled]
https://nuget.org/api/v2/
2. Internal package source [Enabled]
\\network_fileshare\nuget_packages\
C:\repository_root_path>Source\.nuget\nuget_2.7.40808.exe sources
Registered Sources:
1. NuGet official package source [Enabled]
https://nuget.org/api/v2/
2. Internal package source [Enabled]
\\network_fileshare\nuget_packages\
3. https://www.nuget.org/api/v2/ [Disabled]
https://www.nuget.org/api/v2/
所以问题是:NuGet 中是否在 2.5 和 2.6 版本之间引入了一个错误,导致该<clear />
元素被忽略,或者我们的解决方案根目录中的 NuGet.Config 文件有问题?