`dotnet build` and `dotnet restore` hangs forever without any error
Asked Answered
S

3

7

I installed VS2019 with .NET5 SDK on Windows 10. Today it stops working. VS2019 cannot build any .NET project, without showing any error.

I tried to run dotnet build and dotnet restore. It hangs forever without any error. Screenshot: dotnet restore hangs forever without any error

Earlier today my C drive was full. I moved the C:\Users\<user>\.nuget directory to D:\Temp\.nuget, and created a junction point mklink /J C:\Users\<user>\.nuget D:\Temp\.nuget. After I resized my C drive, I moved that directory back. This may be the cause of problem.

I tried to uninstall my .NET 5 SDK, but it does not allow me to do so. Screenshot: .NET 5 SDK was installed with VS2019

I tried to reinstall VS2019 with manually cleanup everything. The problem remains.

Is there anything that I can do before reinstall OS? Thank you.

Scribe answered 17/9, 2021 at 1:55 Comment(4)
SysInternals ProcMon can sometimes help find IO that looks like it's causing problems. Otherwise cloning the NuGet.Client repo and debugging it (ok, you'll need to remove the junction and free up enough disk space to restore the packages that NuGet needs for itself), but if you figure out why it's freezing, then you can fix it and send a pull request to the NuGet team. Otherwise, please get a memory dump when it's frozen, and use VS's feedback tool to share the memory dump with the NuGet team so we can investigate.Avowed
Also, when you said "I moved that directory back", does that also mean you deleted the junction? If not, try completely deleting ~/.nuget. If you don't have an internet connection with a download quota, there's no need to backup and restore the files in there, as NuGet will re-download on the first restore that needs the package.Avowed
Yes, I deleted the junction and physically restored the .nuget directory, the problem remains. I also reinstalled VS 2019. Still have the problem. My Internet connection has no issues. Since I can no longer use .net in my Windows, I installed .net SDK inside WSL and now using it from there.Scribe
BTW - after I reinstall VS2019, I found that msbuild -t=restore and msbuild works, however dotnet restore and dotnet build still hangs forever silently.Scribe
M
1

I tried instead nuget restore, and instead of hanging it gave a result of something like this:

The file 'random.name' could not be accessed because it is being used by another process.

Using procexp I did a file handle search for the file name that was mentioned and found the process (Rider backend in my case) that had the file open. After killing that process I was able to do a restore successfully.

NOTE: nuget.exe must be downloaded (from https://www.nuget.org/downloads) and does not come with VS.

procexp.exe also must be downloaded and is available from https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer

Maiduguri answered 5/9, 2023 at 19:36 Comment(0)
A
0

If you want to move NuGet's global packages folder to a different location/drive, NuGet has built-in support, so no need to use a junction: https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file

So, edit your %appdata%\NuGet\nuget.config file, so it looks something like this:

<configuration>
  <config>
    <add key="globalPackagesFolder" value="d:\Temp\.nuget" />
  </config>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>
Avowed answered 18/9, 2021 at 15:47 Comment(0)
A
0

For MAC / Linux :

Make sure you dont have suspended proccess of dotnet running in the background:

ps -ef | grep "dotnet restore"

If you do, kill them first with:

kill -9 <SOME-PROCESS-ID>

Now retry dotnet restore

That was the issue for me

Alehouse answered 28/8 at 10:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.