简体   繁体   English

如何在.NET Core上注册新的NuGet包源?

[英]How to register new NuGet package source on .NET Core?

I'm struggling to add new NuGet source to store private packages. 我很难添加新的NuGet源来存储私有包。 I have already tried to add config into my .csproj like this post suggests 已经尝试将配置添加到我的.csproj中,就像这篇帖子所说的那样

<?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="Artifactory-DEV" value="https://theluggage-agct.gray.net/artifactory/api/nuget/nuget-institutional-development-local" protocolVersion="3"/>
  </packageSources>
</configuration>

I also tried this but was not able to find an equivalent in dotnet nuget . 也尝试了这个,但无法找到dotnet nuget的等价物。

nuget sources Add -Name "MyServer" -Source \\myserver\\packages nuget sources添加-Name“MyServer”-Source \\ myserver \\ packages

OBS: I'm not using Visual Studio 2017 and currently using Ubuntu. OBS:我没有使用Visual Studio 2017,目前正在使用Ubuntu。

It's a shame that the user ffa didn't post their comment as an answer, because it's correct. 令人遗憾的是,用户ffa没有将他们的评论作为答案发布,因为这是正确的。 The XML is supposed to be in a file named nuget.config . XML应该位于名为nuget.config的文件中。

Also, if you have a newish dotnet SDK/CLI installed, you can also run dotnet new nugetconfig and it will create the file from a basic template for you. 此外,如果您安装了新的dotnet SDK / CLI,您还可以运行dotnet new nugetconfig ,它将为您创建基本模板的文件。 NuGet docs have some information about how settings are applied if you care, but generally people put their nuget.config files in the root of their repository, or in the same place as their .sln file. NuGet文档提供了一些关于如何应用设置的信息,但通常人们将nuget.config文件放在其存储库的根目录中,或者放在与.sln文件相同的位置。

There is another way. 还有另一种方式。

dotnet add package <PACKAGE> -s <SOURCE>

The problem is that I need to add -s every single time I want to add a package from a certain private repo. 问题是我需要在每次添加-s时添加来自某个私有仓库的包。

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

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