visual-studio - 安装依赖多个源的 NuGet 包

标签 visual-studio nuget nuget-server

我的工作有一个私有(private) NuGet 存储库。我可以从它和 nuget.org 安装软件包。当私有(private)存储库中存储的包依赖于 nuget.org 上托管的包时,我遇到了问题。

例如,我的私有(private)仓库托管了一个包 P1。 P1 依赖于托管在 nuget.org 上的 P2。如果使用我的私有(private)仓库设置为源执行“安装包 P1”,我会收到一条错误消息,说它找不到依赖项 P2。这是有道理的,因为它在私有(private)仓库中寻找 P2,但它托管在 nuget.org 上。到目前为止,解决方法是从 nuget.org 安装 P2,然后从私有(private)仓库安装 P1。虽然这在技术上可行,但它很乏味,并且会使向团队其他成员销售 NuGet 变得困难。

无论如何我可以使用多个来源运行 install-package 吗?我试过将一个列表传递给 -Source 参数,但到目前为止已经得到

NuGet.config 由 Visual Studio 管理,因此每次在 Visual Studio 中运行 nuget 命令时,我对其所做的任何更改都会被清除。我尝试在解决方案级别添加一个额外的 nuget.config 文件,但据我所知它被忽略了。我已经尝试了几次 install=package 命令的访问,但它们通常看起来像这样:

Install-Package P1 -Source https://api.nuget.org/v3/index.json,http://privatefeed.com

这里的引用是 NuGet.config 文件,但更改它似乎是徒劳的。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="Private Nuget" value="http://privatefeed.com" />
  </packageSources>
  <disabledPackageSources>
    <add key="Microsoft and .NET" value="true" />
  </disabledPackageSources>
  <activePackageSource>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </activePackageSource>
</configuration>

最佳答案

使用 NuGet.exe,您可以重复 -Source指定多个包源的选项。

例子:

nuget install P1 -Source https://api.nuget.org/v3/index.json -Source http://privatefeed.com

使用包管理控制台 (PowerShell) 似乎无法指定多个源。但是,如果没有 -Source指定,然后使用 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="Private Nuget" value="http://privatefeed.com" />
  </packageSources>
</configuration>

在与解决方案相同的目录中另存为 NuGet.Config,并将其添加到版本控制中。

请注意,您可能必须重新加载 Visual Studio 才能使配置更改生效。

现在您无需配置即可安装软件包-Source .

例子:
Install-Package P1

关于visual-studio - 安装依赖多个源的 NuGet 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35779205/

相关文章:

c++ - 为什么 Visual Studio 2008 突出显示内部作为 C++ 代码中的关键字?

c# - 具有 ProjectReference 依赖项的 NuGet 版本控制

visual-studio-2013 - Visual Studio 在哪里保留它自己的 nuget.exe 副本?

c# - 获取别名列总和的 SQL 子查询

c++ - 在 VS2010 中为平台工具集 v90 构建 C++ CLR 应用需要 Visual Studio 2008

c# - 远程调试托管应用程序

NuGet 包还原 - "Package restore is disabled by default. To give consent, open the Visual Studio Options dialog"

xamarin - 更新 Xamarin 时出现问题 : unable to resolve dependencies

visual-studio-2017 - Nuget本地提要搜索缓慢

msbuild - 商业nuget包的许可表达式