Fix StaticWebAssets FUTDC not tracking referenced project changes#53426
Fix StaticWebAssets FUTDC not tracking referenced project changes#53426
Conversation
|
Thanks for your PR, @@oroztocil. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a Visual Studio Fast Up-to-Date Check (FUTDC) design-time timing issue in Static Web Assets for Blazor solutions with referenced projects, ensuring referenced-project changes (e.g., scoped CSS outputs) are correctly tracked so stale endpoint manifests aren’t reused at runtime.
Changes:
- Adds
ResolveReferencedProjectsStaticWebAssetsConfigurationto the design-time FUTDC input dependency chain so the referenced-projects UTDC manifest file is generated before it is read.
| $(CollectUpToDateCheckInputDesignTimeDependsOn); | ||
| ResolveStaticWebAssetsConfiguration; | ||
| ResolveProjectStaticWebAssets; | ||
| ResolveReferencedProjectsStaticWebAssetsConfiguration; |
There was a problem hiding this comment.
Adding ResolveReferencedProjectsStaticWebAssetsConfiguration to the design-time FUTDC input chain means this target will now run frequently during design-time builds. That target currently writes $(StaticWebAssetReferencesUpToDateCheckManifestPath) using WriteLinesToFile with Overwrite="false" (append) in Microsoft.NET.Sdk.StaticWebAssets.References.targets, which can cause the manifest file to grow with duplicate/stale entries across repeated evaluations and potentially degrade FUTDC performance. Consider adjusting the referenced target to overwrite (or otherwise de-dupe) the file when it is generated during design-time evaluation so the tracked inputs remain bounded and accurate.
| ResolveReferencedProjectsStaticWebAssetsConfiguration; |
There was a problem hiding this comment.
I wanted to have this change as a separate PR (as it is an independent problem, only made more noticeable by the primary fix here). However, added it to this PR.
src/StaticWebAssetsSdk/Targets/Microsoft.NET.Sdk.StaticWebAssets.Design.targets
Show resolved
Hide resolved
test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsDesignTimeTest.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsDesignTimeTest.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsDesignTimeTest.cs
Show resolved
Hide resolved
4a344b4 to
673b001
Compare
The design-time target CollectStaticWebAssetInputsDesignTime reads referenced project build manifest paths from staticwebassets.references.upToDateCheck.txt. However, this file is written by the build-time target ResolveReferencedProjectsStaticWebAssetsConfiguration, which has not run yet when VS evaluates the design-time dependency chain on initial project load. The file does not exist, the read is skipped, and VS CPS caches the empty result. Subsequent builds create the file but the design-time cache is never invalidated. This causes the Server project's FUTDC to miss changes in referenced projects' static web assets (e.g. scoped CSS bundles), skipping the Server rebuild and leaving stale fingerprints in the endpoints manifest. Fix by adding ResolveReferencedProjectsStaticWebAssetsConfiguration to CollectUpToDateCheckInputDesignTimeDependsOn so the references file is written during design-time evaluation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
WriteLinesToFile in ResolveReferencedProjectsStaticWebAssetsConfiguration uses Overwrite=false, which appends referenced project manifest paths on every build instead of replacing the file contents. This causes the file to grow indefinitely with duplicate entries. Change to Overwrite=true. The WriteOnlyWhenDifferent=true attribute is already set, so the file timestamp will only change when the content actually differs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add a regression test that exercises the design-time FUTDC input collection on a clean obj folder (no prior build). This covers the scenario where VS evaluates FUTDC inputs on initial project load before any build has occurred. The existing test CollectUpToDateCheckInputOutputsDesignTime_IncludesReferencedProjectsManifests runs a full build first, so staticwebassets.references.upToDateCheck.txt already exists when the design-time targets read it. The new test skips the prior build and invokes the design-time targets directly, asserting that referenced project manifest paths are still included in UpToDateCheckInput. This would fail without the fix in Design.targets that adds ResolveReferencedProjectsStaticWebAssetsConfiguration to the design-time dependency chain. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
673b001 to
1e478f0
Compare
Problem
When a Blazor Web App with WebAssembly + Global interactivity has a
.razor.cssfile modified in the Client project, the Server project's build is skipped by VS's Fast Up-to-Date Check (FUTDC). The Server's.staticwebassets.endpoints.jsonmanifest retains stale fingerprints and ETags, causing the app to fail at runtime with "An unhandled error has occurred."Fixes #53425
Fixes dotnet/aspnetcore#65738
Investigation
See #53425 for the analysis of the problem.
Change
Microsoft.NET.Sdk.StaticWebAssets.Design.targetsAdded
ResolveReferencedProjectsStaticWebAssetsConfigurationtoCollectUpToDateCheckInputDesignTimeDependsOn. This ensures the references file is written during design-time evaluation, beforeCollectStaticWebAssetInputsDesignTimetries to read it.Microsoft.NET.Sdk.StaticWebAssets.References.targetsChanged
Overwrite="false"toOverwrite="true"on theWriteLinesToFilecall. The file is fully populated from@(_ReferenceManifestPath)on each build, so there is no need to append. The existingWriteOnlyWhenDifferent="true"attribute ensures the file timestamp only changes when the content actually differs, preserving correct FUTDC behavior.Risk
ResolveReferencedProjectsStaticWebAssetsConfigurationcallsGetStaticWebAssetsProjectConfigurationon referenced projects, which is a metadata-only call (it does not resolve actual assets). The expensiveResolveReferencedProjectsStaticWebAssetstarget is not added to the design-time chain.