简体   繁体   English

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

[英]Default package source for NuGet defaulting to newly added source and not All or nuget.org

I added a NuGet 'Package source' to Visual Studio since we have an internal server at work.我在 Visual Studio 中添加了一个 NuGet 'Package source',因为我们有一个内部服务器在工作。

Visual Studio now always defaults to my internal server and cannot find most of our NuGet packages until I switch the package source to All or nuget.org . Visual Studio 现在总是默认为我的内部服务器,并且在我将包源切换到Allnuget.org之前找不到我们的大部分 NuGet 包。

This is a minor inconvenience, but for the past few weeks, I have been doing many more clicks every time I need to work with the NuGet package manager.这是一个小小的不便,但在过去的几周里,每次我需要使用 NuGet 包管理器时,我都会进行更多的点击。 Can anyone tell me how to default to All instead of having it always default to Internal nuget ?谁能告诉我如何默认为All而不是始终默认为Internal nuget

nuget 默认为内部包服务器

Can anyone tell me how to default to All instead of having it always default to Internal nuget?谁能告诉我如何默认为 All 而不是始终默认为 Internal nuget?

To my knowledge, the default package source of NuGet Package Manager depends on the order of package source and the property of activePackageSource in nuget.config .据我所知,NuGet 包管理器的默认包源取决于包源的顺序和nuget.configactivePackageSource属性。

The order of package source:包源顺序:

When you open NuGet Package Manager setting, Tools->Options->NuGet Packager Manager->Package Source, you will notice that there are up and down arrows for package source:打开NuGet Package Manager设置,Tools->Options->NuGet Packager Manager->Package Source,你会发现包源有上下箭头:

在此处输入图片说明

NuGet Package Manager will give priority for default NuGet package source in the top of the package source list. NuGet 包管理器将优先考虑包源列表顶部的默认 NuGet 包源。 For example, if I set NuGet package source LocalServer at the top of that list, when I create a new project, the default NuGet source will be changed to LocalServer :例如,如果我将 NuGet 包源LocalServer设置在该列表的顶部,当我创建一个新项目时,默认的 NuGet 源将更改为LocalServer

在此处输入图片说明

However , this priority of default NuGet source can easily be broken by the property of activePackageSource in nuget.config .但是默认 NuGet 源的这种优先级很容易被 nuget.config 中的 activePackageSource 属性破坏

Open the nuget.config file from %appdata%\\NuGet\\NuGet.config, add the following code:从 %appdata%\\NuGet\\NuGet.config 打开 nuget.config 文件,添加以下代码:

  <activePackageSource>
    <add key="LocalServer2" value="D:\LocalServerTest" />
  </activePackageSource>

Restart Visual Studio , then create a new project, you will find the default NuGet source change to the LocalServer2 :重新启动 Visual Studio ,然后新建一个项目,你会发现默认的 NuGet 源代码更改为LocalServer2

在此处输入图片说明

So , if you want to default nuget.org instead of having it always default to Internal nuget , you can set the NuGet source nuget.org at top of NuGet source list or set the nuget.org as activePackageSource in the nuget.config:因此,如果您想默认nuget.org而不是始终默认为Internal nuget ,您可以在 NuGet 源列表顶部设置 NuGet 源nuget.org或在nuget.org设置为activePackageSource

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

Update for comment:更新评论:

Is there no way to default to All?有没有办法默认为全部? Maybe you can suggest defaulting to All (looks like you work for MS)也许你可以建议默认为 All(看起来你为 MS 工作)

if you want to set the default NuGet source to All , you can use the setting below in nuget.config :如果要将默认 NuGet 源设置为All ,可以在nuget.config使用以下设置:

  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM