How to Fix Missing CSS & JS Files at Build Time in Visual Studio 17.12

Last week we addressed the most annoying problem of Visual Studio 17.12, the messed up NuGet audit for vulnerabilities. This gives us now the chance to talk about the second big problem we may run into in Visual Studio 17.12: the missing CSS and JS files when we build our web applications.

In Visual Studio 17.11 we could build the application without any problems. Just updating Visual Studio to 17.12 got us this annoying error:

System.InvalidOperationException: No file exists for the asset at either location 'wwwroot\css\project.css' or 'wwwroot\css\project.css'. at Microsoft.AspNetCore.StaticWebAssets.Tasks.StaticWebAsset.ComputeFingerprintAndIntegrity(String identity, String originalItemSpec) at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssets.Execute() eLog2.Arzt.Web C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets 662

If you take a closer look at the error, you see that Visual Studio runs .Net 9 to build the application. That did not go well with the .Net 8 application and WebCompiler.

This time I could find an issue on GitHub that had a solution for it: we need a global.json file that pins the SDK to the latest version of .Net 8:

dotnet new globaljson --sdk-version 8.0.404 --roll-forward latestFeature

This creates us the global.json file with these settings:

1
2
3
4
5
6
{
  "sdk": {
    "rollForward": "latestFeature",
    "version": "8.0.404"
  }
}

If we have a global.json file in place, we can compile our .Net 8 web applications without a problem. I hope this solves your problem as well.