如何在.Net Core项目的解决方案中包含NuGet软件包? [英] How do I include NuGet packages in my solution for .Net Core projects?

查看:237
本文介绍了如何在.Net Core项目的解决方案中包含NuGet软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于经典的.Net项目,如果我添加了对NuGet包的引用,它将被下载到packages文件夹中,并且可以将其与我的其余代码一起检查到源代码控制中。这样,任何开发人员都可以下载代码以及NuGet软件包,而不必设置软件包源来单独下载软件包。 .Net Core项目不是这样工作的。似乎没有解决方案的packages文件夹,并且每个开发人员都应设置自定义软件包的源代码并在获得代码时下载软件包。有没有一种方法可以配置.Net Core项目使其像经典的.Net项目一样执行并管理程序包文件夹?

With classic .Net projects, if I added a reference to a NuGet package, it would get downloaded to a packages folder and I could check that into source control along with the rest of my code. This allowed any developer to download the code, along with the NuGet packages, without having to set up a package source to separately download the packages. This is not how .Net Core projects work. There does not seem to be a packages folder for the solution, and it is up to each developer to set up the custom package source and download the packages when they get the code. Is there a way to configure the .Net Core project to do like the classic .Net projects did and manage a packages folder?

推荐答案

许多NuGet行为可以通过 NuGet.Config 文件进行控制(请参阅此参考以获取更多详细信息)

A lot of NuGet behaviour can be controlled via NuGet.Config files (See this reference for more details)

如果放置<$ c解决方案旁边的$ c> NuGet.Config 文件,您可以覆盖将软件包还原到的位置:

If you place a NuGet.Config file next to the solution with the following content, you can override the location that the packages will be restored into:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="globalPackagesFolder" value=".\packages" />
  </config>
</configuration>

如果问题是您需要在每台计算机上的VS中设置其他源,则也可以通过存储库中的NuGet.Config添加这些源,以便VS在打开解决方案时会选择要使用的供稿:

If the problem is that you'd need to set up additional sources in VS on every machine, you can also add those sources via a NuGet.Config in your repository so VS will pick up the feeds to use when opening a solution:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="CompanyFeed" value="https://my.company.com/private/nuget" />
  </packageSources>
</configuration>

如果没有提要来托管软件包,并且需要在解决方案中包含软件包,则可以使用在NuGet.Config中还包含 .nupkg 文件的目录:

If you have no feed to host packages and need to include packages with the solution, you can use a directory containing .nupkg files as well in NuGet.Config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="local" value=".\NuGetPackages" />
  </packageSources>
</configuration>

这篇关于如何在.Net Core项目的解决方案中包含NuGet软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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