Summary: 我们有一个脚本,它从我们的解决方案存储库中的命令行运行nuget.exe . 我们如何配置NuGet仅使用特定的包源(而不是在机器范围或用户配置中列出的任何内容)?
从NuGet文档中,可以阅读以下有关_2686815的内容:
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/
So the question is :在版本2.5和2.6之间是否已经在NuGet中引入了一个错误,以便忽略 <clear />
元素,或者我们在解决方案根目录中的NuGet.Config文件中有什么问题?
1 回答
这是NuGet中的confirmed as a bug . 该修复程序已分配给release 2.7.2 .