0
votes

I want to change nuget package folder but it doesn't work. I tried very much tricks but not work. I restart many times VS but not work.

My config:

  • Visual Studio Community 2019
  • Windows 10 1909 x64

I have a VS solution folder

  • MyProjectSln\
    • HelloWorld\
      • bin
      • nuget_packages
      • NuGet.Config

I want VS studio nuget package manager console use the "NuGet.Config" file and put all packages downloaded in "nuget_packages"

So nuget packages must be in D:\MyProjetSln\HelloWorld\nuget_packages.

Content example of D:\MyProjetSln\HelloWorld\NuGet.Config :

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <config>
        <add key="globalPackagesFolder" value=".\nuget_packages" />
        <!-- I have also tried with repositoryPath but not work -->
    </config>
</configuration>

The xml syntax is correct in my case (in my file).

Example, when i execute the command "install-package NUnit" from Package Manager Console, it put downloaded packages in D:\MyProjectSln\packages\ and I don't want that.

Thank you for helping !

2
Whats your use case for forcing the package location? - stuartd
I just want a different structure of my project - Dylan
"The globalPackagesFolder is a global cache of NuGet packages. This is where NuGet downloads NuGet packages to as a machine cache. NuGet may clean out the cache when too many packages are stored here." - doesn't sound like this is what you want to use, then. Source: stackoverflow.com/a/39920838/43846 - stuartd
Are you looking for RestorePackagesPath? - stuartd

2 Answers

1
votes

Just as this document said, the new nuget.config file must be under the same level directory of the project folder rather than put the file inside the project folder.

In other words, it must be located in at least the solution directory or a higher-level directory.

Note: if you use this way, it will act on all the projects in the same level directory and all the projects in the sub directory.

So you should put the new nuget.config file on the D:\MyProjetSln.

Then modify its content as:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <config>
         <add key="repositoryPath" value="HelloWorld\nuget_packages" />
    </config>
</configuration>

Then, close VS and then reopen your project to enable that function.

In my side,

enter image description here

enter image description here

1
votes

At the time of writing this message, what I want is not possible at the moment.

Maybe it will be a feature later.