dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.49k stars 10.03k forks source link

Rebuild fails when fingerprinting compiled TypeScript in VS 17.12.0 #58948

Open kaleidocore opened 1 day ago

kaleidocore commented 1 day ago

Is there an existing issue for this?

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

cal-tlabwest commented 18 hours ago

I also get this problem in .NET 8 Microsoft.NET.Sdk.Razor projects after installing .NET 9 SDK / VS 17.12:

5>  Using "DefineStaticWebAssets" task from assembly "C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\..\tasks\net472\Microsoft.NET.Sdk.StaticWebAssets.Tasks.dll".
5>  Task "DefineStaticWebAssets"
5>    Task Parameter:RelativePathPattern=wwwroot/**
5>    Task Parameter:SourceType=Discovered
5>    Task Parameter:
5>        FingerprintPatterns=
5>            Initializer
5>                    Expression=#[.{fingerprint}]!
5>                    Pattern=*.lib.module.js
5>            MvcJsModule
5>                    Pattern=*.cshtml.js
5>            ComponentsJsModule
5>                    Pattern=*.razor.js
5>            MvcScopedCss
5>                    Pattern=*.cshtml.css
5>            ComponentsScopedCss
5>                    Pattern=*.razor.css
5>            JsModuleManifest
5>                    Pattern=*.modules.json
5>    Task Parameter:SourceId=MyProject
5>    Task Parameter:FingerprintCandidates=True
5>    Task Parameter:
5>        CandidateAssets=
5>            wwwroot\background.png
5>                    CopyToOutputDirectory=Never
5>                    CopyToPublishDirectory=PreserveNewest
5>                    ExcludeFromSingleFile=true
5>            wwwroot\tlab.css
5>                    CopyToOutputDirectory=Never
5>                    CopyToPublishDirectory=PreserveNewest
5>                    ExcludeFromSingleFile=true
5>            wwwroot\tlab.min.css
5>                    CopyToOutputDirectory=Never
5>                    CopyToPublishDirectory=PreserveNewest
5>                    ExcludeFromSingleFile=true
5>            tsconfig.json
5>                    CopyToOutputDirectory=Never
5>                    CopyToPublishDirectory=PreserveNewest
5>                    ExcludeFromSingleFile=true
5>            _Imports.razor
5>                    CopyToOutputDirectory=Never
5>                    ExcludeFromSingleFile=true
5>                    Pack=false
5>            Scripts\init.ts
5>                    CopyToOutputDirectory=Never
5>            Scripts\tlab.ts
5>                    CopyToOutputDirectory=Never
5>            Styles\tlab.scss
5>                    CopyToOutputDirectory=Never
5>            Styles\height.scss
5>                    CopyToOutputDirectory=Never
5>            Styles\scroll.scss
5>                    CopyToOutputDirectory=Never
5>            Styles\width.scss
5>                    CopyToOutputDirectory=Never
5>    Task Parameter:ContentRoot=F:\source\MyProject\wwwroot\
5>    Task Parameter:BasePath=_content/MyProject
5>    Accepted asset 'wwwroot\background.png' for pattern 'wwwroot/**' with relative path 'background.png'
5>    Computing fingerprint and integrity for asset 'wwwroot\background.png'
5>    Fingerprinting asset 'background.png' as 'background#[.{fingerprint}]?.png' because it didn't match any pattern
5>    Accepted asset 'wwwroot\tlab.css' for pattern 'wwwroot/**' with relative path 'tlab.css'
5>    Computing fingerprint and integrity for asset 'wwwroot\tlab.css'
5>    C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(662,5): error : System.InvalidOperationException: No file exists for the asset at either location 'wwwroot\tlab.css' or 'wwwroot\tlab.css'.
5>    C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(662,5): error :    at Microsoft.AspNetCore.StaticWebAssets.Tasks.StaticWebAsset.ComputeFingerprintAndIntegrity(String identity, String originalItemSpec)
5>    C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(662,5): error :    at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssets.Execute()
5>  Done executing task "DefineStaticWebAssets" -- FAILED.

The .css files are compiled with BuildWebCompiler2022 from .scss.

balachir commented 12 hours ago

@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