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

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

问题描述

对于经典的 .Net 项目,如果我添加了对 NuGet 包的引用,它将被下载到包文件夹中,我可以将其与我的其余代码一起检查到源代码管理中.这允许任何开发人员下载代码以及 NuGet 包,而无需设置包源来单独下载包.这不是 .Net Core 项目的工作方式.解决方案好像没有packages文件夹,每个开发者自己设置自定义包源,拿到代码后下载包.有没有办法像经典的 .Net 项目一样配置 .Net Core 项目并管理包文件夹?

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)

如果您将 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天全站免登陆