Reputation: 139
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?
Upvotes: 6
Views: 7272
Reputation: 53
Here is complete description on what we have done: Force a reference to be absolute using Visual Studio
In summery:
Upvotes: 0
Reputation: 6301
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.
Upvotes: 3
Reputation: 2458
You can specify where the packages folder should be placed (or change the name of it) via the nuget.config file.
See: NuGet Configuration Settings or Specify ‘packages’ Folder Location
Upvotes: 1