Using Microsoft Visual Studio 2022 to build a C# Web API project with .NET 6 Framework, the project builds fine on one machine. I cloned the same source code repository into a different machine, but when building in the new machine I get the following error:

    FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

   at Microsoft.AspNetCore.Razor.Tasks.StaticWebAssetsManifest.ComputeManifestHash()
   at Microsoft.AspNetCore.Razor.Tasks.StaticWebAssetsManifest.Create(String source, String basePath, String mode, String manifestType, ReferencedProjectConfiguration[] referencedProjectConfigurations, DiscoveryPattern[] discoveryPatterns, StaticWebAsset[] assets)
   at Microsoft.AspNetCore.Razor.Tasks.GenerateStaticWebAssetsManifest.Execute()
    ResultsMonitor.API  C:\Program Files\dotnet\sdk\6.0.300\Sdks\Microsoft.NET.Sdk.Razor\targets\Microsoft.NET.Sdk.Razor.StaticWebAssets.targets    411 
Severity    Code    Description Project File    Line    Suppression State
Error       FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
   at Microsoft.AspNetCore.Razor.Tasks.StaticWebAssetsManifest.ComputeManifestHash()
   at Microsoft.AspNetCore.Razor.Tasks.StaticWebAssetsManifest.Create(String source, String basePath, String mode, String manifestType, ReferencedProjectConfiguration[] referencedProjectConfigurations, DiscoveryPattern[] discoveryPatterns, StaticWebAsset[] assets)
   at Microsoft.AspNetCore.Razor.Tasks.GenerateStaticWebAssetsManifest.Execute()
    ResultsMonitor.API  C:\Program Files\dotnet\sdk\6.0.300\Sdks\Microsoft.NET.Sdk.Razor\targets\Microsoft.NET.Sdk.Razor.StaticWebAssets.targets    411 

Error

Furthermore, on the new machine:

  1. If I use JetBrains Rider 2022.1.1 to open the same project, it just builds and runs fine.
  2. If I do a "dotnet build" from the terminal, build also succeeds.

What is wrong with Visual Studio 2022? I even uninstalled and reinstalled Visual Studio 2022 and the .NET 6 SDK for Visual Studio

🔴 No definitive solution yet