【问题标题】:Is there a way to configure NuGet to ignore unavailable package sources?有没有办法将 NuGet 配置为忽略不可用的包源?
【发布时间】:2021-09-06 15:19:11
【问题描述】:

在 Visual Studio 2017 中开发时,我结合使用标准 NuGet 包源和我工作的公司的包源。

要访问那些公司包源,我必须连接到我们公司的 VPN。

不幸的是,这意味着无论我在开发什么,我都必须始终连接到我们公司的 VPN,否则 NuGet 会给我这个:

尝试添加源“http://[one of my company's package sources]”时抛出异常“System.AggregateException”。请确认您的所有在线软件包来源都可用。 发生一个或多个错误。 无法加载我公司包源http://[one的服务索引]。 发送请求时出错。 无法解析远程名称:'[我公司的包源之一]'

如果我尝试使用仅托管在我公司服务器上的软件包,这将是有意义的。但即使我专门将包源下拉菜单设置为 nuget.org,我也会收到此错误。

有一个问题需要修复,但它已经使用了两年,没有任何活动迹象:install fails when a nuget Source is unavailable even when this is not the selected Source #2614

那么,有没有办法配置 NuGet 以忽略丢失的包源?

【问题讨论】:

    标签: nuget


    【解决方案1】:

    正如in this answer 解释的那样,Visual Studio 2017 的行为是设计使然,但也许您可以使用自定义 nuget.config 作为解决方法(也在该答案中解释)。

    【讨论】:

      【解决方案2】:

      以下是配置 NuGet 以忽略某些源的方法。

      如果您将所有非公司代码放在一个文件夹结构中,那么您可以在根目录中放置一个如下所示的nuget.config 文件:

      <?xml version="1.0" encoding="utf-8"?>
      <configuration>
        <disabledPackageSources>
          <add key="My Company's NuGet Source" value="true" />
        </disabledPackageSources>
      </configuration>
      

      如果您不确定该密钥应该是什么,请从命令行运行 nuget sources

      >nuget sources
      Registered Sources:
      
        1.  nuget.org [Enabled]
            https://api.nuget.org/v3/index.json
        2.  My Company's NuGet Source [Disabled]
            https://path/to/the/nuget
        3.  Microsoft Visual Studio Offline Packages [Enabled]
            C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
      

      这也是验证nuget.config 是否被检测到的好方法。 Disabled 来自我的 nuget.config 文件;如果我在公司代码文件夹中运行 nuget sources,数字 2 显示为 Enabled

      您可以在此处找到有关nuget.config 结构的完整详细信息:

      nuget.config reference

      【讨论】:

        猜你喜欢
        • 2010-11-18
        • 1970-01-01
        • 2020-02-17
        • 2016-02-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-02
        • 1970-01-01
        相关资源
        最近更新 更多