-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add TypeScript Static Web Assets integration #52302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,178 @@ | ||||||||||||||||
| <!-- | ||||||||||||||||
| *********************************************************************************************** | ||||||||||||||||
| Microsoft.NET.Sdk.StaticWebAssets.TypeScript.targets | ||||||||||||||||
|
|
||||||||||||||||
| WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have | ||||||||||||||||
| created a backup copy. Incorrect changes to this file will make it | ||||||||||||||||
| impossible to load or build your projects from the command-line or the IDE. | ||||||||||||||||
|
|
||||||||||||||||
| Copyright (c) .NET Foundation. All rights reserved. | ||||||||||||||||
| *********************************************************************************************** | ||||||||||||||||
| --> | ||||||||||||||||
|
|
||||||||||||||||
| <!-- | ||||||||||||||||
| Provides integration between the Microsoft.TypeScript.MSBuild NuGet package and | ||||||||||||||||
| ASP.NET Core Static Web Assets for Razor Class Libraries. | ||||||||||||||||
|
|
||||||||||||||||
| Problem: | ||||||||||||||||
| The TypeScript MSBuild package outputs compiled .js files to wwwroot, which is treated | ||||||||||||||||
| as an input folder by the Static Web Assets SDK. However, TypeScript compilation runs | ||||||||||||||||
| during the Compile phase, AFTER Static Web Assets discovery has already occurred. | ||||||||||||||||
|
|
||||||||||||||||
| This creates two problems: | ||||||||||||||||
| 1. Clean build: TypeScript outputs are not discovered as static web assets because | ||||||||||||||||
| they don't exist yet when ResolveProjectStaticWebAssets runs. | ||||||||||||||||
| 2. Rebuild: The Razor SDK's default globbing adds wwwroot files to Content. During Clean, | ||||||||||||||||
| TypeScript targets delete the .js files, but Content items persist in memory. | ||||||||||||||||
| When Build runs, DefineStaticWebAssets fails because it finds Content items | ||||||||||||||||
| referencing files that no longer exist. | ||||||||||||||||
|
|
||||||||||||||||
| Solution: | ||||||||||||||||
| 1. Hook into ResolveStaticWebAssetsInputsDependsOn to register TypeScript outputs | ||||||||||||||||
| as static web assets AFTER compilation. | ||||||||||||||||
| 2. Remove TypeScript outputs from Content before CoreClean and ResolveProjectStaticWebAssets | ||||||||||||||||
| to prevent stale item references. | ||||||||||||||||
| --> | ||||||||||||||||
| <Project ToolsVersion="14.0"> | ||||||||||||||||
|
|
||||||||||||||||
| <!-- | ||||||||||||||||
| Target: ResolveTypeScriptStaticWebAssetsConfiguration | ||||||||||||||||
|
|
||||||||||||||||
| Sets up the path for the TypeScript manifest file. | ||||||||||||||||
| DependsOnTargets ResolveStaticWebAssetsConfiguration to ensure | ||||||||||||||||
| _StaticWebAssetsManifestBase is defined. | ||||||||||||||||
| --> | ||||||||||||||||
|
||||||||||||||||
| <!-- | |
| Target: ResolveTypeScriptStaticWebAssetsConfiguration | |
| Sets up the path for the TypeScript manifest file. | |
| DependsOnTargets ResolveStaticWebAssetsConfiguration to ensure | |
| _StaticWebAssetsManifestBase is defined. | |
| --> |
javiercn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
javiercn marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this before the target definitions
javiercn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| <!-- | |
| Write manifest file to track registered assets across builds. | |
| WriteOnlyWhenDifferent prevents unnecessary timestamp changes for incremental builds. | |
| FileWrites ensures the manifest is cleaned up during Clean target. | |
| --> |
javiercn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| <!-- | |
| Define endpoints for TypeScript assets. | |
| This creates the endpoint entries that map URL paths to assets, | |
| which are needed for the runtime to serve the files correctly. | |
| --> |
Uh oh!
There was an error while loading. Please reload this page.