ChatGPT解决这个技术问题 Extra ChatGPT

.Net Core and NuGet

I installed .net core from this site. Playing with it led to a number of related package management questions:

The dotnet restore command proceeded to "install" .net core NuGet packages. Where were those packages "installed"? A new folder was not created. The dotnet restore for 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 the restore also 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 was dnxcore50. 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 restore command were listed as beta. Odd. I thought .Net Core was in RC1, not beta. Confused by this. Why this behavior?

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?).

"I thought .Net Core projects kept all their dependencies locally." is not covered by any of the answers. Simply speaking, those dependencies become local only when you use dotnet publish to generate deployment packages. The self-contained deployment mode would grab all dependencies to the same folder, docs.microsoft.com/en-us/dotnet/core/deploying This thread was unfortunately posted before Microsoft created the new Docs site, so any future reader should go and check out the new Docs.

V
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

In NuGet 3+, you can use the NuGet CLI's following command to get the global-packages folder location

nuget locals global-packages -list

Check out following links for more details about NuGet

http://blog.nuget.org/20151008/NuGet-3-What-and-Why.html

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.


The dotnet restore was executed for a "hello world" console application, not a ASP.Net app. So there must be a different answer for #2. And for #3, yes I agree they went to a global location...but that is not the default behavior of NuGet, nor is it the advertised behavior of .Net Core. So #3 still needs more investigation. However, I will mark your response as the answer - and I will ask again as a separate stack overflow question.
The console app has quite a bit of Nuget packages especially with the Core framework. So no matter what you will notice lot of restoring. You are correct Reg #3, I came across this very good article at github. github.com/aspnet/Home/wiki/Package-Locations
the console app has quite a bit of NuGet packages. Yes, that is absolutely true. But I am asking why it has many dependencies. The question is why? Also, your github article link isn't working.
That's because the template Console App needs some extra .Net libraries that are not natively part of the .Net Core. These extra .Net libraries are packaged into Nuget packages and so they show up as dependencies. The link for github should work. github.com/aspnet/Home/wiki/Package-Locations
On Linux you'll find the downloaded NuGet packages in your home directory in the hidden folder, /home/me/.nuget. NuGet will download the package the first time it's been requested and stored here for use across all your projects - this works much like maven for the java world.
D
Dibran

I just found out that there's another location for NuGet packages used in .NET core projects. Its located at:

C:\Users\[User]\.nuget\packages

I think that this location contains regular .NET Framework packages.

Update: Thanks to brappleye3, here's a link to the documentation regarding dotnet restore.


Link to source? Would be nice to see where this is documented - there are likely other nuggets of wisdom nearby. Also, I believe this is the default Nuget location for everything (except Core projects), isn't it?
I added packages to a .NET Core project and they ended up in this location rather than the location in the accepted answer.
Just in case anyone is wondering where the location is for osx/linux: Per the dotnet-restore command docs, "[The nuget package cache] is found in the .nuget/packages directory in the user's home directory on all operating systems (for example, /home/user1 on Linux or C:\Users\user1 on Windows)." docs.microsoft.com/en-us/dotnet/articles/core/tools/…
J
Jester

I'm working with .Net Core 2.x and, I think, NuGet 4.x. Found Package locations here:

C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\


What you posted is irrelevant to the question. The accepted answer is not perfect, but you should not try to update it this way.
It is relevant: more current libraries, new path. Just a little more recent information. No need to downvote for adding some info.
I am down-voting not only because it is irrelevant, but incorrect. You can go and build a clean machine with only .NET SDK installed to see yourself. You won't see the folder you indicate on it at all. Don't mislead readers if your intention is to help them out.
This is helpful. I do have packages in this directory. Thanks @Jester