.net - Nuget 包存储在哪里?

标签 .net nuget package-managers

我阅读了 Microsoft 文档 https://learn.microsoft.com/it-it/nuget/consume-packages/managing-the-global-packages-and-cache-folders :

Whenever you install, update, or restore a package, NuGet manages packages and package information in several folders outside of your project structure

因此,如果我为我的解决方案安装 Bootstrap Package MyFirstSolution,则该包应下载到我的文件夹 global-packages 上,并且对它的引用将添加到我的解决方案中.

如果当我创建 MySecondSolution 并想要添加 Bootstrap VS 时一切正常,则应该只添加对我的项目的引用,但从技术上讲,我必须从包管理器再次下载它,而不仅仅是添加对为 MyFirstSolution 下载的现有包。

同时,每当我通过第三方下载项目时,即使我已经从我制作的其他项目中安装了它,我也必须重新安装所有使用的软件包。

最佳答案

以下是当我安装已安装在另一个项目中(即:在缓存中)的 Newtonsoft.Json 13.0.1 时包管理器的输出:

Restoring packages for D:\Sources\github\Orace\SO\SO_72936295\SO_72936295.csproj...
Installing NuGet package Newtonsoft.Json 13.0.1.
Writing assets file to disk. Path: D:\Sources\github\Orace\SO\SO_72936295\obj\project.assets.json
Successfully installed 'Newtonsoft.Json 13.0.1' to SO_72936295
Executing nuget actions took 247 ms
Time Elapsed: 00:00:00.7045858
========== Finished ==========

Time Elapsed: 00:00:00.0864676
========== Finished ==========

以下是我安装从未安装在我的计算机上的 FluentAssertions 6.7.0 时包管理器的输出(即:不在缓存中):

Restoring packages for D:\Sources\github\Orace\SO\SO_72648958\SO_72648958.csproj...
  GET https://api.nuget.org/v3-flatcontainer/fluentassertions/index.json
  OK https://api.nuget.org/v3-flatcontainer/fluentassertions/index.json 136ms
  GET https://api.nuget.org/v3-flatcontainer/fluentassertions/6.7.0/fluentassertions.6.7.0.nupkg
  OK https://api.nuget.org/v3-flatcontainer/fluentassertions/6.7.0/fluentassertions.6.7.0.nupkg 23ms
  GET https://api.nuget.org/v3-flatcontainer/system.configuration.configurationmanager/index.json
  OK https://api.nuget.org/v3-flatcontainer/system.configuration.configurationmanager/index.json 137ms
  GET https://api.nuget.org/v3-flatcontainer/system.configuration.configurationmanager/4.4.0/system.configuration.configurationmanager.4.4.0.nupkg
  OK https://api.nuget.org/v3-flatcontainer/system.configuration.configurationmanager/4.4.0/system.configuration.configurationmanager.4.4.0.nupkg 19ms
  GET https://api.nuget.org/v3-flatcontainer/system.security.cryptography.protecteddata/index.json
  OK https://api.nuget.org/v3-flatcontainer/system.security.cryptography.protecteddata/index.json 150ms
  GET https://api.nuget.org/v3-flatcontainer/system.security.cryptography.protecteddata/4.4.0/system.security.cryptography.protecteddata.4.4.0.nupkg
  OK https://api.nuget.org/v3-flatcontainer/system.security.cryptography.protecteddata/4.4.0/system.security.cryptography.protecteddata.4.4.0.nupkg 17ms
Installed System.Configuration.ConfigurationManager 4.4.0 from https://api.nuget.org/v3/index.json with content hash gWwQv/Ug1qWJmHCmN17nAbxJYmQBM/E94QxKLksvUiiKB1Ld3Sc/eK1lgmbSjDFxkQhVuayI/cGFZhpBSodLrg==.
Installed System.Security.Cryptography.ProtectedData 4.4.0 from https://api.nuget.org/v3/index.json with content hash cJV7ScGW7EhatRsjehfvvYVBvtiSMKgN8bOVI0bQhnF5bU7vnHVIsH49Kva7i7GWaWYvmEzkYVk1TC+gZYBEog==.
Installed FluentAssertions 6.7.0 from https://api.nuget.org/v3/index.json with content hash PWbow/R3MnYDP8UW7zh/w80rGb+1NufGoNJeuzouTo2bqpvwNTFxbDwF6XWfFZ5IuquL2225Um+qSyZ8jVsT+w==.
Installing NuGet package FluentAssertions 6.7.0.
Writing assets file to disk. Path: D:\Sources\github\Orace\SO\SO_72936295\obj\project.assets.json
Successfully installed 'FluentAssertions 6.7.0' to SO_72936295
Successfully installed 'System.Configuration.ConfigurationManager 4.4.0' to SO_72936295
Successfully installed 'System.Security.Cryptography.ProtectedData 4.4.0' to SO_72936295
Executing nuget actions took 43 ms
Time Elapsed: 00:00:01.5080716
========== Finished ==========

Time Elapsed: 00:00:00.1262123
========== Finished ==========

如您所见,在第二种情况下,实际上有一些下载(例如:GET https://api.nuget.org/v3-flatcontainer/Fluentassertions/index.json)。

在这两种情况下,都有一个将 Assets 文件写入磁盘。部分。
这就是项目中 NuGet 的实际安装。
如果您手动编辑.csproj添加NuGet,这部分仍然需要执行。
您可以通过解决方案资源管理器中解决方案根项的上下文菜单来完成此操作。
单击恢复 NuGet 包

关于.net - Nuget 包存储在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72936295/

相关文章:

c# - 为什么不能推断出这些泛型类型?

c# - 如何在没有等待运算符的情况下获取返回值

c# - 为平板电脑和 WindowMobile 开发 winforms 应用程序

NuGet 包失败,出现 "Unable to find ' @(_OutputPathItem->'%(FullPath)..."

c# - 从 Nuget 包中自动提取 native 和托管 DLL

ubuntu - 设备或资源繁忙 - Docker

c# - 如何准确测量Azure Web应用程序中的 "data out"?

android - 无法安装 Xamarin.Android.Support.v4

python - dist-packages 和 site-packages 有什么区别?

arm - Buildroot包管理