Local source of nuget packages doesn't exist
Asked Answered
B

12

65

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.

Braswell answered 12/6, 2019 at 9:26 Comment(1)
I intentionally want to point to that path which may or may not exist, is it possible to tell nuget to stop freaking out and just ignore it if the folder doesnt exist?Doublereed
K
111

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.

Kiona answered 12/6, 2019 at 13:33 Comment(7)
The 'dotnet new nugetconfig' did the trick for me, thank you very much!Wendy
Editing nuget.config works for me. Do you know why did this happen in the first place ?Civilization
I had this problem and it turned out that my Nuget.config file was in a .nuget folder. Once I relocated the file to the solution folder, the issue resolved. This link provides some additional information. linkHirsh
I had to open Package source options and update a custom package source there.Meilen
It happened when I got fed up with Visual Studio, decided to use Rider and deleted Visual Studio. This answer helped me to fix the problem.Trimaran
The 'dotnet new nugetconfig' did the trick for me too. ThanksRegurgitate
Deleting the offending package source in the Nuget.config file resolved the issue. I had to restart VS though.Crabber
C
37

I had a similar error preventing nuget restore command from working but with a different path:

C:\Program Files\dotnet\sdk\3.1.100\NuGet.targets(132,5): error : The local source C:\work\nuget doesn't exist.

I fixed it by removing that path from:

Visual Studio ▶ Tools ▶ Options ▶ Nuget Package Manager ▶ Package Sources

Update:

On macOS and Linux you may delete ~/.nuget

Crabtree answered 15/4, 2020 at 9:47 Comment(4)
I had a similar error but with a different path: %appdata%\Roaming\NuGet\NuGet.Config. Editing this config fixed my errorWorcestershire
Where is this file on macOS and Linux?Henderson
@AaronFranke probably here for macOS: /usr/local/share/dotnet/ if ARM64 and /usr/local/share/dotnet/x64/dotnet/ if x64, or maybe here: /usr/local/share/dotnet/dotnet. And for Linux: ~/.dotnetCrabtree
I ended up deleting ~/.nuget on macOS and this worked.Henderson
D
16

Open a PowerShell window and enter the following code: dotnet new nugetconfig

Dwarfism answered 25/8, 2021 at 10:8 Comment(0)
C
10

I have used more visual method for resolving this issue look 👇

✍edit1: Possible reason, your project may have offline packages referenced to your very first computer. And than, when you go trough another computer, it cant recognise the local source path of your offline packages.

  1. List item
  2. List item
  3. List item
  4. List item it is done!
Condyle answered 19/11, 2021 at 11:26 Comment(0)
S
7

Although the error seems not to be related to nuget, it is actually related.

Open PowerShell and run the following command:

dotnet new nugetconfig
Surgery answered 25/5, 2022 at 11:17 Comment(0)
R
3

Because the message says that the folder doesn't exist, I created it, and the problem disappeared. Yes, it was so simple like that.

BTW there is a discussion on GitHub on similar trouble, and Rob Relya from Microsoft wrote:

This is by design behavior. We fail restore if any of your sources are not reachable. We don't want to create a folder for you, in case it was a typo.

From my point of view, it's OK.

Rodd answered 16/3, 2021 at 22:24 Comment(1)
Thanks! The command above or the other solutions didn't work.Pacesetter
S
1

I also had the same issue on DevOps (image 1,2) .net core restore task. I resolved this by just removing the Offline package reference (image 3) from the NuGet.config file.

image 1 enter image description here

image 2 enter image description here

image 3 enter image description here

Spy answered 28/4, 2020 at 6:7 Comment(0)
R
1

I had trouble understanding the answers, maybe some of them had the solution. What helped me in the end:

I edited C:\Windows\System32\config\systemprofile\AppData\Roaming\NuGet\NuGet.Config
and removed <packageSources> with the value "..\NuGet.Config"

Not sure how it got there, the actual value might be different for everyone.

Rainarainah answered 17/5, 2022 at 10:21 Comment(0)
M
1

I was getting the following error.

error NU1301: The local source 'C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages' doesn't exist.

Earlier I accidentally deleted the entire shared folder itself( drive was full, so was cleaning up) and so the error.

After reading the @zivkan's answer at the top, I created a file by name NuGetPackages. But that did not solve the problem, because we need to create a folder(directory), not file. So after creating a directory, by name NuGetPackages, dotnet restore worked again.

Of course you need admin permission to create that folder.

Maxine answered 18/11, 2023 at 14:7 Comment(0)
A
0

I was upgrading my dontet MVC project from .Net core 2.2 to 3.1 and adding a reference to the Microsoft.Extensions.Configuration.AzureAppConfiguration. when I had this issue. All I did is removed the "add key="Local" value=".References" from nuget.config and the issue is solved. I was able to reference the package,

Anele answered 25/9, 2020 at 16:9 Comment(0)
G
0

Check your Registered Nuget Sources. You can do it by running this command:

dotnet nuget list source

If some of the sources is missing or wrong you have to remove it:

dotnet nuget remove source "Your Package Source Name"
Goff answered 1/7 at 21:34 Comment(0)
P
0

Firstly I faced the issue when I cloned the MAUI repo from GitHub and tried to run it.

The error was

The local source '/Users/david ortinau/work/Localstorage' doesn't exist.

What I did was just delete the NuGet.Config which automatically reinitialized the nuggets. and Issue solved.

Proselytize answered 7/7 at 14:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.