Nuget的默认软件包源默认为新添加的源,而不是All或nuget.org

Mar*_*rio 8 visual-studio nuget visual-studio-2017

因为我们有一个内部服务器在工作,所以我向Visual Studio添加了一个nuget“包源”。

现在,Visual Studio始终默认使用我的内部服务器,并且在我将包源切换为All或之前,无法找到我们的大多数nuget包。nuget.org

这是一个小小的麻烦,但是在过去的几周里,每次我需要与nuget软件包管理器一起工作时,我都会做更多的点击。谁能告诉我如何默认All而不是始终默认为Internal nuget

nuget默认为内部软件包服务器

Leo*_*SFT 11

谁能告诉我如何默认全部而不是始终将其默认为Internal nuget?

据我所知,NuGet软件包管理器的默认软件包来源取决于软件包来源的顺序和activePackageSourcein中的属性nuget.config

包源码的顺序:

当您打开NuGet软件包管理器设置时,在工具->选项-> NuGet打包程序管理器->软件包源中,您会注意到软件包源有上下箭头:

在此处输入图片说明

NuGet软件包管理器将在软件包来源列表顶部为默认nuget软件包来源赋予优先级。例如,如果我LocalServer在该列表的顶部设置了nuget包源,则在创建新项目时,默认的nuget包源将更改为LocalServer

在此处输入图片说明

但是可以通过nuget.config中activePackageSource的属性轻松打破默认nuget源的优先级

从%appdata%\ NuGet \ NuGet.config打开nuget.config文件,添加以下代码:

  <activePackageSource>
    <add key="LocalServer2" value="D:\LocalServerTest" />
  </activePackageSource>
Run Code Online (Sandbox Code Playgroud)

重新启动Visual Studio,然后创建一个新项目,您会发现默认的nuget源更改为LocalServer2

在此处输入图片说明

因此,如果要默认nuget.org而不是始终将其默认设置为Internal nuget,则可以nuget.org在nuget源列表的顶部设置nuget源,或在nuget.config中将设置nuget.orgactivePackageSource

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

更新评论:

没有办法默认为全部吗?也许您可以建议默认为“全部”(看起来像您为MS工作)

如果要将默认的nuget源设置为All,则可以在下面的设置中使用nuget.config

  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
Run Code Online (Sandbox Code Playgroud)

  • @LeoLiu-MSFT,Visual Studio 2022 没有用于包源的向上和向下箭头。 (3认同)
  • @LeoLiu-MSFT 看起来“全部”选项已被弃用,令人遗憾的是https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file#activepackagesource (2认同)
  • VS 2022 不仅没有向上/向下箭头,编辑 nuget.config 以添加对“all”的引用也不再有效。 (2认同)