4

I have same problem like someone have here:

Visual Studio get stuck on "Restoring packages for solution"

I try the following:

  1. Clear nuget cache from Tools menu. and temp, %temp% folders from RUN command.
  2. Clear visual studio cache from here. C:\Users\Dell\AppData\Roaming\Microsoft\VisualStudio\17.0_27e1b93f
  3. Clear .vs hidden folder of solution.
  4. Clean and Rebuild Solution. But stuck into Restoring Nuget packages...)
  5. I wait 15 minutes. But nothing happened.... (There's bug here?)
  6. I only use less than 7 nuget packages from nuget.org

Here's Visual Studio Log:

Microsoft Visual Studio Community 2022
Version 17.2.6
VisualStudio.17.Release/17.2.6+32630.192
Microsoft .NET Framework
Version 4.8.03761

Installed Version: Community

.NET Core Debugging with WSL   1.0
.NET Core Debugging with WSL

ASP.NET and Web Tools 2019   17.2.393.26812
ASP.NET and Web Tools 2019

Azure App Service Tools v3.0.0   17.2.393.26812
Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools   17.2.393.26812
Azure Functions and Web Jobs Tools

BusinessObjectEditor   1.0
Information about my package

C# Tools   4.2.0-4.22281.5+8d3180e5f00d42f0f0295165f756f368f0cbfa44
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

CreateLayoutWizard   1.0
Create layout wizard.
   
Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

NuGet Package Manager   6.2.1
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Razor (ASP.NET Core)   17.0.0.2218101+885a343b00bcab620a90c1550c37dafd730ce984
Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools   17.0.62204.01010
Microsoft SQL Server Data Tools

TypeScript Tools   17.0.10418.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   4.2.0-4.22281.5+8d3180e5f00d42f0f0295165f756f368f0cbfa44
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   17.1.0-beta.22329.1+702b8e77f5fbfe21e6743324c1750503e02f182d
Microsoft Visual F# Tools

Visual Studio IntelliCode   2.2
AI-assisted development for Visual Studio.

More Information:

  1. I use old *.csproj project template (non-sdk)
  2. I use PackageReference not packages.config
  3. .NET 4.8
  4. Windows 7
  5. No proxy used. and official nuget.org/api/.... works in browser.

NOTE: this happened when I re-installed operating system.... Sometimes it took time. Sometimes it freeze and hangs on Restoring Nuget packages... message

Please how to solve that?

  • 1
    What if you try using the nuget.exe outside of visual studio? https://learn.microsoft.com/en-us/nuget/consume-packages/install-use-packages-nuget-cli – Timothy G. Aug 01 '22 at 01:01
  • I never used that before. visual studio should do everything.. –  Aug 01 '22 at 01:02
  • 1
    It should yes - but even under the hood, Visual Studio is using this. I would see what it does using a command line only, external of Visual Studio. If it works fine that way, perhaps reinstall Visual Studio? – Timothy G. Aug 01 '22 at 01:03
  • nuget.exe restore *.sln also hanging... I re-installed visual studio... please did you met that problem before? and how you overcome that –  Aug 01 '22 at 01:04
  • I have not myself encountered this. Are you using a VPN? If so, try turning that off maybe. Is whatever your package source (sounds like https://www.nuget.org/) reachable on your network? At this point I'm just making guesses at things to try. – Timothy G. Aug 01 '22 at 01:09

4 Answers4

3

We found that if there is delisted nuget package in our csproj then this can cause the same behavior.

For example: https://www.nuget.org/packages/Microsoft.AppCenter.Crashes/4.4.0

This package is delisted and once this package was upgraded to a version which is listed the restore loop went away.

  • I am thinking how it gets build correctly even if this is delisted. I removed all nugets from cache and then restored it and they were all restored correctly. It seems that package is still available even if it is not present on the Nuget website. Did you check how it actually works? – prf Jul 06 '23 at 14:14
2

According to your description I think the problem is that you used PackageReference and use nuget.exe to restore the packages.

We can see from this link that For projects migrated to PackageReference, use msbuild -t:restore to restore packages instead.

You can try msbuild -t:restore instead of nuget restore ***.csproj to restore packages if you are using PackageReference. For more details, please refer to the above link

Jingmiao Xu-MSFT
  • 2,076
  • 1
  • 3
  • 10
  • I need to do that within VIsual Studio GUI. Is there any settings to choose what command should executed internally by visual studio.... –  Aug 01 '22 at 15:11
  • I targeting .NET 4.8, old-non sdk *.csproj style. with PackageReference. And have Local Nuget in my local drive. I think when do rebuild it should look to all available nuget package source https://prnt.sc/oIQwomtTy6Jg Should I switch back to packages.config? because non-sdk have bug with PackageReference by default.... Also I don't know why ASP.NET doesn't support PackageReference.. https://prnt.sc/EE9h8c4-KzUH –  Aug 01 '22 at 15:24
  • You take the cake... But I actually don't use msbuild -t as its also freeze/hang. please can you tell Microsoft team as they love you to fix that issue :-). You are a MSFT! –  Aug 01 '22 at 21:26
1

I fixed this by updating the Nuget package source in Visual Studio 2022 on a machine that previously had the Visual Studio 2013 nuget package source

"In the Options window, expand the NuGet Package Manager node and select Package Sources."

package source name: nuget.org

package source: https://api.nuget.org/v3/index.json

https://learn.microsoft.com/en-us/nuget/consume-packages/install-use-packages-visual-studio

nimblebit
  • 473
  • 3
  • 11
  • 22
0

While it is correct to consider the msbuild alternative when using command line, it is still very annoying for anything inside Visual Studio 2022. I am hitting it on many scenarios, like trying to run tests after build was successful.

Fortunately, it is now fixed in the latest Visual Studio 17.5.0 Preview 6.0 https://visualstudio.microsoft.com/vs/preview/

Bruno Guardia
  • 453
  • 4
  • 14