Search code examples
visual-studio-codenugetnuget-package-restore

Local source of nuget packages doesn't exist


After opened the project in another computer and run it on VS Code, the following problem occurred:

C:\Program Files\dotnet\sdk\2.2.300\NuGet.targets(121,5): error : The 
local source C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\' 
doesn't exist.

I found the solution for the VS but no VS Code.


Solution

  • The package source is probably defined in %appdata%\nuget\nuget.config. Edit this file in your favourite xml/text editor (VSCode perhaps?). You should see under a package sources element an add element that adds that file path. Comment out or delete that line.

    If it's not in that file, try running dotnet restore --verbosity normal or just dotnet restore -v n. If you still only get an error message, try running dotnet new nugetconfig, or temporarily create the C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\ directory. NuGet, with normal verbosity, outputs the list of all nuget.config files that were read. Open each one until you find which one defines the local source that does not exist, so you can edit it and remove it. Or just keep the empty directory.

    It's also possible that the package source is defined in a MSBuild file, rather than a nuget.config file. If that's the case, you might need to run dotnet msbuild -pp to generate a pre-processed file (the msbuild with all imports evaluated to create a single, "stand-alone" msbuild file). You then search that file for the path that doesn't exist, then scroll up until you find a comment saying what file it was defined in. You then then choose whether you edit that file.

    However, it may just be easier to create an empty directory at the path.