.Net 核心和 NuGet
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35205092/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.Net Core and NuGet
提问by Brent Arias
I installed .net core from this site. Playing with it led to a number of related package management questions:
我从这个站点安装了 .net core。使用它导致了许多相关的包管理问题:
- The
dotnet restorecommand proceeded to "install" .net core NuGet packages. Where were those packages "installed"? A new folder was not created. - The
dotnet restorefor the "hello world" minimal example required about a hundred NuGet packages, where 99% were presumably irrelevant to the "hello world" app. Granted, a .net native build will remove all that is not needed - but I expected that therestorealso would have grabbed very little (three or four packages, not a hundred). Why this behavior? - I created a second "hello world" project and again ran
dotnet restore. This time no packages were installed at all. It seems all the packages installed the first time-around went into some global location to be shared. I thought .Net Core didn't work that way. I thought .Net Core projects kept all their dependencies locally. The only framework I targeted wasdnxcore50. Why this behavior? - I would like to "uninstall" all these global packages, and try again (just for learning purposes). How might that be accomplished? Remember, as stated in question #1, I don't know where all those files were installed.
- Almost all of the packages installed via the
restorecommand were listed as beta. Odd. I thought .Net Core was in RC1, not beta. Confused by this. Why this behavior?
- 该
dotnet restore命令继续“安装” .net 核心 NuGet 包。这些软件包“安装”在哪里?未创建新文件夹。 - 将
dotnet restore所需约一百名的NuGet包,其中99%的人想必无关的“世界你好”应用中的“Hello World”的小例子。诚然,.net 本机构建将删除所有不需要的内容 - 但我预计它们restore也会占用很少(三或四个包,而不是一百个)。为什么会有这种行为? - 我创建了第二个“hello world”项目并再次运行
dotnet restore. 这次根本没有安装任何软件包。似乎第一次安装的所有软件包都进入了某个全球位置以进行共享。我认为 .Net Core 不能那样工作。我认为 .Net Core 项目在本地保留了所有依赖项。我针对的唯一框架是dnxcore50. 为什么会有这种行为? - 我想“卸载”所有这些全局包,然后再试一次(仅用于学习目的)。这怎么可能实现?请记住,如问题 #1 所述,我不知道所有这些文件的安装位置。
- 几乎所有通过该
restore命令安装的软件包都被列为测试版。奇怪的。我认为 .Net Core 是在 RC1 中,而不是测试版。对此一头雾水。为什么会有这种行为?
I'm also curious of what documentation could/would have explained all this to me. I tried googling for each of these questions, and found nothing (perhaps just horrible google-fu?).
我也很好奇什么文档可以/会向我解释这一切。我试着用谷歌搜索这些问题,但一无所获(也许只是可怕的 google-fu?)。
采纳答案by Vivek N
Update:
更新:
- The nuget packages are installed in a global location. By default it used to be ..\Users\[YourUserFolder]\.dnx\packages but it appeared to have changed to ..\Users\[YourUserFolder]\.nuget\packages
- nuget 包安装在全局位置。默认情况下,它曾经是 ..\Users\[YourUserFolder]\.dnx\packages 但它似乎已更改为 ..\Users\[YourUserFolder]\.nuget\packages
In NuGet 3+, you can use the NuGet CLI's following command to get the global-packages folder location
在 NuGet 3+ 中,您可以使用 NuGet CLI 的以下命令获取 global-packages 文件夹位置
nuget locals global-packages -list
Check out following links for more details about NuGet
查看以下链接以了解有关 NuGet 的更多详细信息
https://docs.nuget.org/ndocs/consume-packages/configuring-nuget-behavior
https://docs.nuget.org/ndocs/tools/nuget.exe-cli-reference#locals
https://docs.nuget.org/ndocs/consume-packages/configuring-nuget-behavior
https://docs.nuget.org/ndocs/tools/nuget.exe-cli-reference#locals
The default ASP.Net template has so many packages. Since you tried first time, it tried get all those 100s of packages
You already had those packages in your nuget global locations, it skipped the restore.
Delete all contents under packages folder (location indicated in 1)
Some of the beta packages are there. You can go to project.json file (available under the web root) and play with the dependencies section.
默认的 ASP.Net 模板有很多包。自从您第一次尝试以来,它尝试获取所有这些 100 个包
您的 nuget 全局位置中已经有了这些包,它跳过了还原。
删除packages文件夹下的所有内容(位置如1所示)
一些测试包在那里。您可以转到 project.json 文件(在 web 根目录下可用)并使用依赖项部分。
回答by Dibran
I just found out that there's another location for NuGet packages used in .NET core projects. Its located at:
我刚刚发现 .NET 核心项目中使用的 NuGet 包还有另一个位置。它位于:
C:\Users\[User]\.nuget\packages
C:\Users\[User]\.nuget\packages
I think that this location contains regular .NET Framework packages.
我认为这个位置包含常规的 .NET Framework 包。
Update: Thanks to brappleye3, here's a linkto the documentation regarding dotnet restore.
更新:感谢 brappleye3,这里是有关 dotnet restore 的文档的链接。
回答by Jester
I'm working with .Net Core 2.xand, I think, NuGet 4.x. Found Package locations here:
我正在使用.Net Core 2.x和NuGet 4.x。在这里找到包裹位置:
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

