Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 405
KSA Avatar asked Jun 12 '19 09:06

KSA


People also ask

Where are NuGet packages installed locally?

The global-packages folder is where NuGet installs any downloaded package. Each package is fully expanded into a subfolder that matches the package identifier and version number. Projects using the PackageReference format always use packages directly from this folder. When using the packages.

How do I fix a missing NuGet package?

Enable package restore by choosing Tools > Options > NuGet Package Manager. Under Package Restore options, select Allow NuGet to download missing packages. In Solution Explorer, right click the solution and select Restore NuGet Packages.

How do I add a local NuGet package to Visual Studio?

You can configure Visual Studio to automatically generate the NuGet package when you build the project. In Solution Explorer, right-click the project and choose Properties. In the Package tab, select Generate NuGet package on build.


1 Answers

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.

like image 171
zivkan Avatar answered Sep 21 '22 22:09

zivkan