且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在我的 .Net Core 项目解决方案中包含 NuGet 包?

更新时间:2022-05-03 04:31:34

很多 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>