Why does NuGet Package Manager download / copy packages in several places?

I have a directory structure like -

Projects .nuget NuGet.exe NuGet.config NuGet.targets **packages (I want to download package for different solution HERE ONLY)** Sources Applications App1 App1.sln (Solution File) **packages (NuGet downloads packages here first then copies to expected folder, WHY??)** App1 (Porject Directory) App1.csproj App2 App2.sln (Solution File) **packages (NuGet downloads packages here first then copies to expected folder, WHY??)** App2 (Porject Directory) App2.csproj 

I reference the .nuget folder in each solution using the following code

 Project("{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}") = ".nuget", ".nuget", "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx}" ProjectSection(SolutionItems) = preProject ..\..\..\.nuget\NuGet.Config = ..\..\..\.nuget\NuGet.Config ..\..\..\.nuget\NuGet.exe = ..\..\..\.nuget\NuGet.exe ..\..\..\.nuget\NuGet.targets = ..\..\..\.nuget\NuGet.targets EndProjectSection EndProject 

In each project file (.csproj), I reference the common NuGet.targets using

 <Import Project="..\..\..\..\.nuget\NuGet.targets" Condition="Exists('..\..\..\..\.nuget\NuGet.targets')" /> 

In NuGet.config, I added the following line so that it (should) copy packages only to the EXPECTED folder

 <add key="repositoryPath" value="..\packages" /> 

I have mapped the Projects folder to TFS and it asks me to add files in both locations due to the above problem.

+5
source share
1 answer

NuGet will search for the NuGet.config file based on the current solution directory.

Therefore, making the decision App1, if the Projects directory is in the c: \ Projects directory, your App1.sln file will be in the c: \ Projects \ Sources \ Applications \ App1 directory. NuGet will now search for the NuGet.config directory in:

 c:\Projects\Sources\Applications\App1\.nuget\NuGet.Config c:\Projects\Sources\Applications\App1\NuGet.Config c:\Projects\Sources\Applications\NuGet.Config c:\Projects\Sources\NuGet.Config c:\Projects\NuGet.Config c:\NuGet.Config 

After that, he will look in engine nodes, but I will not ignore them now.

When looking at your directory structure, NuGet does not check the Projects.nuget directory. He is not the parent of any of the solution directories.

I would look at the NuGet.Config file with the repositoryPath parameter in the Sources directory or in the Projects directory (not in the .nuget directory). Or it has two NuGet.Config files, one in the App1.nuget directory and one in the App2.nuget directory.

0
source

All Articles