aspnetcore: Rebuild fails when fingerprinting compiled TypeScript in VS 17.12.0

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

After upgrading to VS 17.12.0 / .Net9 SDK: Solution Rebuild fails during fingerprinting of static assets, if those assets are (re-)produced during build.

In particular this applies to TypeScript files that are compiled to .js files under wwwroot/ during the build process, using the standard Microsoft.TypeScript.MSBuild (5.6.2) nuget.

This worked in VS 17.11.x / .Net8 SDK. The project is a .Net8 project.

NB: It is also unclear why fingerprinting is even applied to .Net8 projects, and how to turn it off.

Expected Behavior

Rebuild should not fail. Analysis of static assets produced during build should be scheduled so that fingerprinting succeeds.

Steps To Reproduce

Minimal repro here: https://github.com/kaleidocore/TSBuildFail

The minimal repro is based on the basic TypeScript template/example described here: https://learn.microsoft.com/en-us/visualstudio/javascript/tutorial-aspnet-with-typescript?view=vs-2022

Typically Clean+Build succeeds, but Rebuild fails.

Exceptions (if any)

System.InvalidOperationException: No file exists for the asset at either location 'wwwroot\js\app.js' or 'wwwroot\js\app.js'.
   at Microsoft.AspNetCore.StaticWebAssets.Tasks.StaticWebAsset.ComputeFingerprintAndIntegrity(String identity, String originalItemSpec)
   at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssets.Execute()

.NET Version

9.0.100

Anything else?

Other static assets produced during build also fails in the same way, e.g. .scss -> .css using WebCompiler.

A temporary workaround for the issue is to force a downgrade of the .Net SDK using a global.json in the root folder:

{
	"sdk":
	{
		"version": "8.0.404",
		"rollForward": "latestPatch"
	}
}

I believe the core of this issue is actually much older, but the new Fingerprinting feature puts focus on it by failing completely, whereas it previously sort of “worked” - we have had very similar issues when publishing our projects (dotnet publish solution.sln ...) in previous versions of Visual Studio / .Net. It often appears random or timing based whether those same static files produced during build are actually included in the publish output. We’ve had to work around it by adding additional build steps such as Clean, Build, Publish and running it single-threaded.

I also suspect these issues are related: https://github.com/dotnet/aspnetcore/issues/57147 https://github.com/dotnet/aspnetcore/issues/58748

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 10
  • Comments: 27 (8 by maintainers)

Most upvoted comments

<StaticWebAssetFingerprintingEnabled>false</StaticWebAssetFingerprintingEnabled> works for .net9.0.

But doesn’t work for .net8.0. So our compiles with <TargetFrameworks>net9.0; net8.0</TargetFrameworks> break…

Yep, which is what I (and literally anyone else who makes Blazor assemblies) am targeting right now in my projects. Also, this thread needs to be re-opened because there is not actually a functioning fix yet.

For css files that were minified using https://marketplace.visualstudio.com/items?itemName=Failwyn.BundlerMinifier64 it worked for me with:

 <PropertyGroup>
  <PrepareForBuildDependsOn>
   BundleMinify;$(PrepareForBuildDependsOn)
  </PrepareForBuildDependsOn>
 </PropertyGroup>

If you are using something else to minify, you will have to find out what they called their build target.

For Typescript I followed the suggestion with the following config:

 <PropertyGroup>
  <PrepareForBuildDependsOn>
   CompileTypeScriptWithTSConfig;
   GetTypeScriptOutputForPublishing;$(PrepareForBuildDependsOn)
  </PrepareForBuildDependsOn>
 </PropertyGroup>

But now I get this error (even with the <Content Remove="wwwroot\js\**" />)

Two assets found targeting the same path with incompatible asset kinds: 
'PROJECTPATH_REMOVED\wwwroot\js\browserWindowOpener.js' with kind 'All'
'PROJECTPATH_REMOVED\wwwroot\js\browserWindowOpener.js' with kind 'All'
for path 'js/browserWindowOpener#[.{fingerprint}]?.js'

For css files that were minified using https://marketplace.visualstudio.com/items?itemName=Failwyn.BundlerMinifier64 it worked for me with:

<PropertyGroup> <PrepareForBuildDependsOn> BundleMinify;$(PrepareForBuildDependsOn) </PrepareForBuildDependsOn> </PropertyGroup> If you are using something else to minify, you will have to find out what they called their build target.

For Typescript I followed the suggestion with the following config:

<PropertyGroup> <PrepareForBuildDependsOn> CompileTypeScriptWithTSConfig; GetTypeScriptOutputForPublishing;$(PrepareForBuildDependsOn) </PrepareForBuildDependsOn> </PropertyGroup> But now I get this error (even with the `<Content Remove="wwwroot\js\**" />`)
Two assets found targeting the same path with incompatible asset kinds: 
'PROJECTPATH_REMOVED\wwwroot\js\browserWindowOpener.js' with kind 'All'
'PROJECTPATH_REMOVED\wwwroot\js\browserWindowOpener.js' with kind 'All'
for path 'js/browserWindowOpener#[.{fingerprint}]?.js'

For css files that were minified using https://www.nuget.org/packages/BuildWebCompiler2022 it worked for me with:

<PropertyGroup>
  <PrepareForBuildDependsOn>WebCompile;$(PrepareForBuildDependsOn)</PrepareForBuildDependsOn>
</PropertyGroup>

I’ve been experiencing a similar error for an ASP.NET Core MVC project that I updated to .NET 9. Rebuilding always fails and all my attempts to fix the issue in the last couple of hours failed.

In the end, this is my workaround: Don’t use rebuild, use clean + build instead

The workaround with <StaticWebAssetFingerprintingEnabled>false</StaticWebAssetFingerprintingEnabled> did not work for me, unfortunately.

<StaticWebAssetFingerprintingEnabled>false</StaticWebAssetFingerprintingEnabled> works for .net9.0.

But doesn’t work for .net8.0. So our compiles with <TargetFrameworks>net9.0; net8.0</TargetFrameworks> break…

Well I’d like to add that I use both Mads BuildWebCompiler and BuildBundlerMinifier and this worked for me:

<PropertyGroup>
  <PrepareForBuildDependsOn>WebCompile;BundleMinify;$(PrepareForBuildDependsOn)</PrepareForBuildDependsOn>
</PropertyGroup>

I’ve filed https://github.com/microsoft/TypeScript/issues/60538 on the typescript repository to improve the integration with ASP.NET Core, I suggest you go and upvote the issue to show interest.

Hopefully we can make this just work out of the box.

For other tools, hooking to PrepareForBuildDependsOn is a good solution. https://github.com/dotnet/aspnetcore/issues/38445 tracks offering official integration

But now I get this error (even with the <Content Remove="wwwroot\js\**" />)

Two assets found targeting the same path with incompatible asset kinds: ‘PROJECTPATH_REMOVED\wwwroot\js\browserWindowOpener.js’ with kind ‘All’ ‘PROJECTPATH_REMOVED\wwwroot\js\browserWindowOpener.js’ with kind ‘All’ for path ‘js/browserWindowOpener#[.{fingerprint}]?.js’

This is because the typescript compiler adds the elements as Content items to the build, the issue here is that on subsequent builds, the elements are present in the wwwroot folder and get included twice. That’s what the <Content Remove="wwwroot\js\** /> line was meant to address, but I’ve now realized based on @kaleidocore comment that the approach was naive.

I’ll post an updated fix and we will document this in the docs.

@Liebeck >

In the end, this is my workaround: Don’t use rebuild, use clean + build instead

That is not a viable option for our build server, or for our devs in the long run. We’ve had some limited success with the proposed solution by @javiercn but it leads to other build problems, in particular with our MAUI hybrid project. I will probably open up a second issue once I have a new minimal repro prepared. For now our only workaround is still the global.json SDK downgrade.

The workaround with <StaticWebAssetFingerprintingEnabled>false</StaticWebAssetFingerprintingEnabled> did not work for me, unfortunately.

Yeah, we’ve had the same experience. That’s why I mentioned in the original post that it’s unclear why fingerprinting is running and how to turn it off.

The missing piece is this one target that removes existing content items before GetTypeScriptOutputForPublishing gets invoked. Ideally, this should be done by the TypeScript SDK itself.

+    <Target Name="RemoveDuplicateTypeScriptOutputs" BeforeTargets="GetTypeScriptOutputForPublishing">
+      <ItemGroup>
+        <Content Remove="@(GeneratedJavaScript)" />
+      </ItemGroup>
+    </Target>

After upgrade to VS 17.12, we experience the same with trying to bundle css. When I “build” the web project, it works. However, doing a “rebuild” on the web project fails.

Image

@javiercn @halter73 this issue also got reported as a regression with VS 17.12 on Developer Community here. Many customers are reporting it. Can you investigate and help determine if the issue is on the runtime side or tooling? Thanks!

cc: @mkArtakMSFT