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?
Asked
Active
Viewed 9,019 times
6
-
Packages.config is merged into the csproj. See [Additions to the csproj format for .NET Core](https://learn.microsoft.com/en-us/dotnet/articles/core/tools/csproj). You now use a `PackageReference` XML element. The Visual Studio package manager still works. – Dustin Kingen Apr 28 '17 at 18:59
-
Is your problem referencing things out of the package cache or lack of a nuget feed to host (private) packages on? – Martin Ullrich Apr 28 '17 at 19:07
1 Answers
15
A lot of NuGet behaviour can be controlled via NuGet.Config
files (See this reference for more details)
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>
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>
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>

Martin Ullrich
- 94,744
- 25
- 252
- 217
-
I tried
and independently. I cannot tell the difference. They both seemed to do the same thing. I was also hoping that the packages would automatically be added to source control, the way they always were in the past with .Net projects. I tried setting that explicitly with , but it did not seem to help. I had to manually add the files to source control, but at least that is possible now that they are under the solution directory. – Eric Apr 29 '17 at 00:17 -
1Don't put .\ in the value, because that won't be cross-platform (won't work on windows as well). – knownasilya May 23 '18 at 15:18
-
1@knownasilya did you try it? Nuget normally normalizes the path. If this stopped working we should report the bug. – Martin Ullrich May 23 '18 at 15:53
-
Yeah, it worked on macOS but not on windows. It made that folder verbatim. – knownasilya May 23 '18 at 20:49
-
1@Eric Per the linked documentation (https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file#config-section): dependencyVersion and repositoryPath apply only to projects using packages.config. globalPackagesFolder applies only to projects using the PackageReference format. Typically the PackageReference is used for newer .NET Core apps that by definition are tiny, and thus rely on many more external references than a .NET Framework library, which can rely on the .NET Framework providing such functionality. – CJBS Oct 18 '18 at 19:05