覆盖默认的 nuget.config 文件

and*_*rea 2 .net msbuild nuget nuget-package nuget-package-restore

我在 .sln 文件与 nuget.config 相同的位置添加了此配置

<packageSources>
    <add key="local repo" value="C:\myproject\nugetRepository" />
</packageSources>
Run Code Online (Sandbox Code Playgroud)

我在 appdata/roaming/NuGet 中也有默认的 nuget.config ,配置如下

<packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
Run Code Online (Sandbox Code Playgroud)

在线阅读时,我了解到根项目中的 nuget.config 应该覆盖默认配置,但是,在使用 MSBuild 构建时,它始终使用 appdata 中的配置!我如何指定使用根项目中的那个?

ziv*_*kan 5

正如NuGet 文档的此页所述,设置是累积的,这意味着两者都会被使用。正如本节中提到的,您可以使用<clear />忽略所有先前读取的nuget.config文件中的源。

<packageSources>
    <clear />
    <add key="local repo" value="C:\myproject\nugetRepository" />
</packageSources>
Run Code Online (Sandbox Code Playgroud)

<clear />在禁用的包源和后备文件夹部分中也有效,这对于可重复构建绝对至关重要的工程团队来说非常重要(例如,共享同一台 CI 机器并写入 a 来nuget.config影响c:\您自己团队的构建是不可接受的)。