如何在msbuild 15.0命令行中指定私有nuget包源?

时间:2018-05-22 12:47:08

标签: .net msbuild visual-studio-2017 nuget nuget-package-restore

在vs 2017中使用msbuild 15.0时是否可以指定私有nuget feed服务器? 我正在使用的当前powershell命令如下:

&$msbuild /t:restore /tv:15.0 /t:Rebuild /p:Configuration=Release

默认情况下,此处仅提取nuget.org的Feed。

4 个答案:

答案 0 :(得分:6)

  

如何在msbuild 15.0命令行中指定私有nuget包源?

如果只想从指定的私有nuget包源恢复nuget包,可以使用属性RestoreSources来指定私有源:

msbuild /t:restore /p:RestoreSources=xxx /tv:15.0 /t:Rebuild /p:Configuration=Release

查看restore target了解更多详情。

答案 1 :(得分:5)

您可以使用/p:RestoreAdditionalSources=…指定其他来源。

此外,使用/restore(MSBuild 15.3+)而不是将Restore与其他目标一起指定,以便正确地重新加载NuGet生成的所有已更改文件。

答案 2 :(得分:1)

MS Build从解决方案根目录中读取NuGet.Config文件。您可以添加新的Nuget.config文件并在其中指定外部存储库。

nuget.config reference

答案 3 :(得分:0)

我向位于 '%appdata%\NuGet\NuGet.Config' 中的 nuget.config 文件添加了一个新的包源,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="anotherSource" value="http://10.2.36.4:53673/nuget" />
  </packageSources>
</configuration>