0

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 !

Dylan
  • 59
  • 2
  • 8
  • Whats your use case for forcing the package location? – stuartd Sep 22 '20 at 22:21
  • I just want a different structure of my project – Dylan Sep 22 '20 at 22:27
  • _"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: https://stackoverflow.com/a/39920838/43846 – stuartd Sep 22 '20 at 22:34
  • Are you looking for [`RestorePackagesPath`](https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore)? – stuartd Sep 22 '20 at 22:37

2 Answers2

1

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

Mr Qian
  • 21,064
  • 1
  • 31
  • 41
  • What is "the peer directory"? – Mary Sep 23 '20 at 04:32
  • 1
    It means the same level directory. – Mr Qian Sep 23 '20 at 05:52
  • but if you have multiple projects in the same solution folder, and you have for example the same package but with different version, how do you do ? Ex: project HelloWorld and project HelloSun And as the document said, we can't have nuget.config in each project , is it correct ? – Dylan Sep 23 '20 at 08:41
  • 1
    As far as I know, it is impossible. In fact, `nuget.config` file is not as flexible as you think, and it cannot be positioned in every project. And the properties of msbuild cannot be recognized by `nuget.config`. And it cannot identify each project and then package nuget into the project folder. So I am afraid that you cannnot get what you want. – Mr Qian Sep 23 '20 at 09:52
  • 1
    If you still want this feature, I suggest you could report this feature on [nuget github](https://github.com/NuGet) or on [our user voice forum](https://developercommunity.visualstudio.com/content/idea/post.html?space=8). – Mr Qian Sep 23 '20 at 09:56
1

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

Maybe it will be a feature later.

Dylan
  • 59
  • 2
  • 8