I hava a solution which contains two Project.
/Solution
.sln
.nuget.config
/ProjectA
.csproj
.nuspec
/ProejctB
.csproj
.nuspec
When I add a dependency ProjectA via nuget.
Project structure is become something like this:
/Solution
.sln
nuget.config
/packages
.nupkg
/lib
.dll
/ProjectA
.csproj
.nuspec
packages.config
/ProejctB
.csproj
.nuspec
Basically, Visual Studio create a packages.config file and put dependency there. And, dependency is added to /packages
folder. Also, .csproj
content changes.(A Reference added which has a relative path to dll inside /packages
folder.)
I have two question.
1- Inside nuget.config file I have put following line. So I expect nuget will use default local repository instead of creating a /packages
folder in solution. How can I prevent creation of a /packages folder in solution. Instead I would like to use "%userprofile%\.nuget\packages"
.
<add key="globalPackagesFolder" value="%userprofile%\.nuget\packages" />
2- When I add the dependency as nuget package. Still .csprj
file is changed and dll's related path is added there as a reference with relative path. Is it ok? Isn't auto generated packages.config
enough. Why also this file is updated.
1- Inside nuget.config file I have put following line. So I expect nuget will use default local repository instead of creating a /packages folder in solution. How can I prevent creation of a /packages folder in solution. Instead I would like to use "%userprofile%.nuget\packages".
You should use below settings in the NuGet.Config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="%userprofile%\.nuget\packages" />
</config>
</configuration>
You can check the test result from below screenshot, the packages is add to the "%userprofile%\.nuget\packages
" folder:
Note: Take care the uppercase and lowercase for the file name and restart the VS after add it.
2- When I add the dependency as nuget package. Still .csprj file is changed and dll's related path is added there as a reference with relative path. Is it ok? Isn't auto generated packages.config enough. Why also this file is updated.
Not, because the Package.config and the HintPath in the .csproj file have different role. The Package.config is used by NuGet to manage the Packages, and the HintPath in the .csproj is used by the Visual Studio reference the path of the Dll file. Both files are need to be updated, otherwise Visual Studio will throw the error "Can not find the reference..."