Reputation: 540
When using the NuGet automatic package restore added in version 2.7, NuGet automatically downloads any missing packages to a packages\ folder located at the solution level. When a solution includes libraries (i.e. git subtree or git submodules) this causes problems as the library projects expect the packages to be downloaded to a packages folder located in their respective solution folder (which is typically nested as a subfolder inside the primary code's solution folder) and do not know to look for the packages in the primary code's solution folder. For example:
primary_code_folder\
->primary_code.sln
->packages\
[various packages downloaded by NuGet]
->primary_code_project\
->library_solution_folder\
--->library_code.sln
--->packages\
[where the library project expects packages to reside]
--->library_code_project\
Potential solutions to this:
nuget.exe restore library_code.sln
in a pre-build event command line command. However, nuget.exe isn't naturally in the solution and isn't (by default) located in a path variable. So it seems that copying nuget.exe into the project may cause later incompatibility as updates would not be pulled in. Perhaps there is a workaround for this?Can anyone share how they have approached this problem? A similar question was asked here (NuGet Automatic Package Restore when using git submodules) for a different situation and the answer does not satisfy the needs I am describing in this post.
Upvotes: 1
Views: 320
Reputation: 11
This can be done by placing multiple nuget.config files, at each folder location, where a sln exists.
Within the nuget.config you need to add the following
<config>
<add key="repositoryPath" value="C:\Temp" />
</config>
or
<config>
<add key="repositoryPath" value="..\..\.." />
</config>
have a look here for more details https://docs.nuget.org/consume/nuget-config-settings
Upvotes: 1