覆盖默认 nuget.config 文件

Overwrite default nuget.config file

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

<packageSources>
    <add key="local repo" value="C:\myproject\nugetRepository" />
</packageSources>

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

<packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>

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

this page of NuGet's docs says, settings are accumulated, meaning both are used. As mentioned in this section 一样,您可以使用 <clear /> 忽略所有以前读取的 nuget.config 文件的来源。

<packageSources>
    <clear />
    <add key="local repo" value="C:\myproject\nugetRepository" />
</packageSources>

<clear /> 在禁用的包源和后备文件夹部分也有效,这对于工程团队来说很重要,因为他们对可重复构建绝对至关重要(例如,有人共享同一台 CI 机器和写一个 nuget.configc:\ 是不可接受的,因为它会影响你自己团队的构建。