Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I specify one central place where all the nuget packages will be installed

Tags:

nuget

How can I specify one central place where all the nuget packages will be installed, so that all projects can refer to the same packages folder.

When 1 project have delete the reference does not depends on another project. so I can easily update the new version nuget in a single folder and works on all.

It will also save disk space in source control.

Can someone give me any suggestions?

like image 776
kalimuthu Avatar asked Aug 28 '13 06:08

kalimuthu


People also ask

How do I change the default location of a NuGet package?

Open %AppData%\NuGet folder, open existing NuGet. Config file. Edit repositoryPath key and set new destination.

Where do NuGet packages get installed?

The global-packages folder is where NuGet installs any downloaded package. Each package is fully expanded into a subfolder that matches the package identifier and version number. Projects using the PackageReference format always use packages directly from this folder. When using the packages.


1 Answers

There are in fact two steps to restoring packages to a different location correctly. Assuming you used Visual Studio (right-click on solution -> Enable package restore) you will have a .nuget directory in the same directory your solution resides. You need to edit two files to get this right.

Edit NuGet.Config Add the repository path setting as specified in the documentation.

<configuration>
  <solution>
    <add key="disableSourceControlIntegration" value="true" />
  </solution>
  <config>
    <add key="repositorypath" value="..\..\packages" />
  </config>
</configuration>

..\packages will mimic the default behavior. The path is relative to the project folder (not the .nuget folder) so ....\ will be the directory up from your project files.

If your projects are really all over the place, consider moving the Nuget.config file to the root of your source tree and configure the repositryPath relative to that location instead. You can of course use full paths as well but that's ugly.

Secondly, you need to remove the solutionDir option from the restore command (they don't tell you to do this anywhere). For that, edit NuGet.targets

Look for the RestoreCommand element and remove the solutionDir argument.

From this: <RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)</RestoreCommand>

To this: <RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch)</RestoreCommand>

Depending on what version of Visual Studio you generated the files with, the actual XML could be different than my example. Just make sure that option is removed and leave everything else the same.

NB: Now that you have changed the location of the packages directory (or even names it something else) you will need to update your project references to point to the new location. Relative paths are obviously recommended. You can do this manually in Visual Studio (painful) or open up the .csproj/.vbproj files and find/replace the HintPath for the reference.

like image 145
BrutalDev Avatar answered Oct 03 '22 10:10

BrutalDev