Nuget的默认软件包源默认为新添加的源,而不是All或nuget.org [英] Default package source for Nuget defaulting to newly added source and not All or nuget.org

查看:498
本文介绍了Nuget的默认软件包源默认为新添加的源,而不是All或nuget.org的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我们有一个内部服务器在工作,所以我向Visual Studio添加了一个nuget包源".

I added a nuget 'Package source' to Visual Studio since we have an internal server at work.

Visual Studio现在始终默认为我的内部服务器,并且在我将包源切换为Allnuget.org

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

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

This is a minor inconvience, but for the past few weeks I have been doing many more clicks every time I need to work with the nuget package manager. Can anyone tell me how to default All instead of having it always default to Internal nuget?

推荐答案

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

Can anyone tell me how to default All instead of having it always default to Internal nuget?

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

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 Packager管理器"->软件包源"中,您会注意到软件包源有上下箭头:

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软件包管理器将在软件包来源列表顶部为默认nuget软件包来源赋予优先级.例如,如果我在该列表的顶部设置了nuget包源LocalServer,则在创建新项目时,默认的nuget包源将更改为LocalServer:

NuGet Package Manager will give priority for default nuget package source in the top of the package source list. 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.config中的activePackageSource的属性轻松打破默认nuget源的优先级.

However, this priority of default nuget source can easily be broken by the the property of activePackageSource in nuget.config.

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

Open the nuget.config file from %appdata%\NuGet\NuGet.config, add following code:

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

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

Restart Visual Studio, then create a new project, you will find the default nuget source change to the LocalServer2:

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

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:

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

更新评论:

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

Is there no way to default to All? Maybe you can suggest defaulting to All (looks like you work for MS)

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

if you want to set the default nuget source to All, you can use below settting in the nuget.config:

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

这篇关于Nuget的默认软件包源默认为新添加的源,而不是All或nuget.org的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆