Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nuget.config ignored completely no matter what

I want to specify where the packages are stored on a nuget restore. Of course, this is documented on MSDN, and of course, it never works....

I have a test solution stored in D:\Development\Test\Test.sln

According to their documentation, nuget no longer looks in the .nuget folder inside the solution folder. Instead it now looks in the solution folder, or further up the chain. So I could store a nuget.config in

  • D:\Development\Test\Nuget.Config
  • D:\Development\Nuget.Config
  • D:\Nuget.Config

Well, I tried all three of them, and restarted Visual studio more times than I am willing to count.

I also read, that they did such a crappy job implementing nuget, that typos inside the nuget.config result in silently ignoring the nuget file. So I thought, that must be it, I made a typo. So I downloaded nuget.exe (latest stable 5.0.2) and issued the commands to configure nuget to put my packages location where I want it.

nuget config -set repositoryPath=D:\Development\test\packages -configfile ..\nuget.config

This is how the XML looks like:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="repositoryPath" value="D:\Development\test\packages" />
  </config>
</configuration>

After configuring Nuget.config using nuget.exe, I again tried any of the previous locations (D:\;D:\Development\;D:Development\Test), restarted visual studio every change of location, richt click solution, choose 'restore nuget packages', and the same result: zero packages are restored to my designated repository path.

So as a last attempt, I tried to nuget restore from the command line:

D:\Development\test>nuget restore test.sln -ConfigFile ..\nuget.config
MSBuild auto-detection: using msbuild version '16.1.76.45076' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\bin'.
Restoring packages for D:\Development\test\test\test.csproj...
Restoring packages for D:\Development\test\ClassLibrary1\ClassLibrary1.csproj...
Committing restore...
Committing restore...
Generating MSBuild file D:\Development\test\ClassLibrary1\obj\ClassLibrary1.csproj.nuget.g.props.
Generating MSBuild file D:\Development\test\test\obj\test.csproj.nuget.g.props.
Writing assets file to disk. Path: D:\Development\test\ClassLibrary1\obj\project.assets.json
Writing assets file to disk. Path: D:\Development\test\test\obj\project.assets.json
Restore completed in 603,63 ms for D:\Development\test\ClassLibrary1\ClassLibrary1.csproj.
Restore completed in 603,6 ms for D:\Development\test\test\test.csproj.

NuGet Config files used:
    D:\Development\nuget.config

It even mentions that it uses my nuget.config, but again, ZERO packages restored in my designated package folder!

I really hope that anybody can tell me in what mysterious way this is supposed to work.

like image 731
bas Avatar asked Jun 24 '19 21:06

bas


People also ask

Is NuGet config necessary?

If you're trying to create a NuGet package from your own code, you do not need a NuGet. config file. The NuGet. config file exists to specify package sources from which packages are installed and updated - i.e. where you consume packages from.

How do I fix a NuGet package error?

Quick solution for Visual Studio usersSelect the Tools > NuGet Package Manager > Package Manager Settings menu command. Set both options under Package Restore. Select OK. Build your project again.

How do I force a NuGet package to reinstall?

Switch to the Browse tab, search for the package name, select it, then select Install). For all packages, delete the package folder, then run nuget install . For a single package, delete the package folder and use nuget install <id> to reinstall the same one.

Where is the default NuGet config?

The default is %userprofile%\.nuget\packages (Windows) or ~/.nuget/packages (Mac/Linux). A relative path can be used in project-specific nuget.config files.


1 Answers

This nuget.config stored in a subfolder on E: works for me in Visual Studio 2019 when I load a solution in that subfolder or below:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="repositoryPath" value="D:\NugetPackages" />
    <add key="globalPackagesFolder" value="D:\NugetPackages" />
    <add key="dependencyVersion" value="Highest" />
  </config>
</configuration>

The key difference is that I also have a globalPackagesFolder entry pointing to the same folder - according to the docs this setting is used by "projects using PackageReference only". I suggest you try adding a globalPackagesFolder entry.

like image 191
Stephen Kennedy Avatar answered Sep 18 '22 00:09

Stephen Kennedy