How do I include NuGet packages in my solution for .Net Core projects?

With classic .Net projects, if I added a reference to the NuGet package, it will be downloaded to the packages folder and I could test this against the original control along with the rest of the code. This allowed any developer to download the code along with the NuGet packages without having to install the package source to download the packages separately. This doesn't work .Net Core. There seems to be no package of packages for the solution, and each developer can set up their own package source and download the packages when they get the code. Is there a way to set up a .Net Core project like classic .Net projects and manage the packages folder?

+3


source to share


1 answer


A lot of NuGet behavior can be controlled through files NuGet.Config

(see this link for more details)

If you place a file NuGet.Config

next to the solution with the following content, you can override the location where the packages will be restored:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="globalPackagesFolder" value=".\packages" />
  </config>
</configuration>

      

If the problem is that you need to set up additional sources in VS on each machine, you can also add those sources via NuGet.Config to your repository so that VS picks up the channels to use when opening the solution



<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="CompanyFeed" value="https://my.company.com/private/nuget" />
  </packageSources>
</configuration>

      

If you don't have a package feed and need to include packages with a solution, you can use the directory containing the files .nupkg

and also in NuGet.Config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="local" value=".\NuGetPackages" />
  </packageSources>
</configuration>

      

+8


source







All Articles