VIsual Studio 2022坚持恢复Nuget包



我遇到了和这里的人一样的问题:

Visual Studio被困在";恢复解决方案的包";

我尝试以下方法:

  1. 从"工具"菜单中清除nuget缓存。和temp,%temp%文件夹
  2. 从这里清除visual studio缓存。C: \Users\Dell\AppData\Roaming\Microsoft\VisualStudio\17.0_27e1b93f
  3. 清除解决方案的.vs隐藏文件夹
  4. 清洁和重建解决方案。但一直在恢复Nuget包…(
  5. 我等了15分钟。但什么也没发生。。。。(这里有虫子吗?(
  6. 我只使用了不到7个来自nuget.org的nuget包

以下是Visual Studio日志:

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.

更多信息:

  1. 我使用旧的*.csproj项目模板(非sdk(
  2. 我使用PackageReference而不是packages.config
  3. .NET 4.8
  4. Windows 7
  5. 未使用代理。官方的nuget.org/api/…在浏览器中工作

注意:这是在我重新安装操作系统时发生的。。。。有时这需要时间。有时它会冻结并挂在Restoring Nuget packages... message

请问如何解决

我们发现,如果在我们的csproj中有被摘牌的nuget包,那么这可能会导致同样的行为。

例如:https://www.nuget.org/packages/Microsoft.AppCenter.Crashes/4.4.0

此程序包已摘牌,一旦此程序包升级到列出的版本,恢复循环就消失了。

根据您的描述,我认为问题在于您使用了PackageReference并使用nuget.exe来恢复包。

我们可以从这个链接中看到,对于迁移到PackageReference的项目,使用msbuild-t:restore来恢复包。

如果使用PackageReference,则可以尝试msbuild -t:restore而不是nuget restore ***.csproj来还原程序包。有关更多详细信息,请参阅以上链接

我通过在以前具有Visual Studio 2013 Nuget包源的机器上更新Visual Studio 2022中的Nuget包源来修复此问题

"在"选项"窗口中,展开"NuGet程序包管理器"节点,然后选择"程序包源">

包源名称:nuget.org

程序包来源:https://api.nuget.org/v3/index.json

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

虽然在使用命令行时考虑msbuild替代方案是正确的,但对于Visual Studio 2022内部的任何东西来说,这仍然非常烦人。我在很多场景中都遇到了它,比如在构建成功后尝试运行测试。

幸运的是,它现在在最新的Visual Studio 17.5.0预览版6.0中得到了修复https://visualstudio.microsoft.com/vs/preview/

最新更新