Repository navigation
Allow to fingerprint Blazor.js - #46988
Conversation
|
Thanks for your PR, @maraf. |
There was a problem hiding this comment.
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (1)
test/Microsoft.NET.Sdk.Razor.Tests/StaticWebAssetsFingerprintingTest.cs:49
- The change from a boolean flag to a string representing the script path means that test inputs now dictate the expected file name directly. Please verify that both cases (e.g., 'main.js' and '_framework/blazor.webassembly.js') are adequately exercised and that any documentation or comments are updated to reflect this change.
public static TheoryData<string, string> WriteImportMapToHtmlData => new TheoryData<string, string>
|
There is a bit of dance to make asset promotion in publish happy. The implementation is based on what we do in runtime to promote hard fingerprinted assets for publish. An alternative would probably be to define these assets as build only and create new assets for publish. I'm not sure if that's a better solution and whether the longer-term goal of not copying these assets to build outputs isn't a way to go |
| <Target Name="_ReplaceFingerprintedBlazorJsForPublish" DependsOnTargets="ProcessPublishFilesForWasm" Condition="'$(WasmBuildingForNestedPublish)' != 'true' and '$(BlazorFingerprintBlazorJs)' == 'true'"> | ||
| <ItemGroup> | ||
| <_BlazorJSStaticWebAsset Include="@(StaticWebAsset)" Condition="'%(FileName)' == '%(_BlazorJSFile.FileName)'" /> | ||
| <_BlazorJSPublishCandidate Include="%(_BlazorJSStaticWebAsset.RelativeDir)%(_BlazorJSStaticWebAsset.FileName).%(_BlazorJSStaticWebAsset.Fingerprint)%(_BlazorJSStaticWebAsset.Extension)" /> | ||
| <_BlazorJSPublishCandidate> | ||
| <RelativePath>_framework/$([System.IO.Path]::GetFileNameWithoutExtension('%(Filename)'))%(Extension)</RelativePath> | ||
| </_BlazorJSPublishCandidate> | ||
| </ItemGroup> | ||
|
|
||
| <DefineStaticWebAssets | ||
| CandidateAssets="@(_BlazorJSPublishCandidate)" | ||
| FingerprintCandidates="true" | ||
| FingerprintPatterns="@(_BlazorJSFingerprintPattern)" | ||
| SourceId="$(PackageId)" | ||
| SourceType="Computed" | ||
| AssetKind="All" | ||
| AssetMergeSource="$(StaticWebAssetMergeTarget)" | ||
| AssetRole="Primary" | ||
| AssetTraitName="WasmResource" | ||
| AssetTraitValue="boot" | ||
| CopyToOutputDirectory="Never" | ||
| CopyToPublishDirectory="PreserveNewest" | ||
| ContentRoot="%(_BlazorJSStaticWebAsset.ContentRoot)" | ||
| BasePath="%(_BlazorJSStaticWebAsset.BasePath)" | ||
| > | ||
| <Output TaskParameter="Assets" ItemName="_BlazorJSPublishStaticWebAssets" /> | ||
| </DefineStaticWebAssets> | ||
| <DefineStaticWebAssetEndpoints | ||
| CandidateAssets="@(_BlazorJSPublishStaticWebAssets)" | ||
| ExistingEndpoints="@(StaticWebAssetEndpoint)" | ||
| ContentTypeMappings="@(StaticWebAssetContentTypeMapping)" | ||
| > | ||
| <Output TaskParameter="Endpoints" ItemName="_BlazorJSPublishStaticWebAssetsEndpoint" /> | ||
| </DefineStaticWebAssetEndpoints> | ||
| <PropertyGroup> | ||
| <_BlazorJSStaticWebAssetFullPath>@(_BlazorJSStaticWebAsset->'%(FullPath)')</_BlazorJSStaticWebAssetFullPath> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <_BlazorJSStaticWebAsset Include="@(StaticWebAsset)" Condition="'%(AssetTraitName)' == 'Content-Encoding' and '%(RelatedAsset)' == '$(_BlazorJSStaticWebAssetFullPath)'" /> | ||
| </ItemGroup> | ||
| <FilterStaticWebAssetEndpoints Condition="'@(_BlazorJSStaticWebAsset)' != ''" | ||
| Endpoints="@(StaticWebAssetEndpoint)" | ||
| Assets="@(_BlazorJSStaticWebAsset)" | ||
| Filters="" | ||
| > | ||
| <Output TaskParameter="FilteredEndpoints" ItemName="_BlazorJSEndpointsToRemove" /> | ||
| </FilterStaticWebAssetEndpoints> | ||
| <ItemGroup> | ||
| <StaticWebAsset Remove="@(_BlazorJSStaticWebAsset)" /> | ||
| <StaticWebAsset Include="@(_BlazorJSPublishStaticWebAssets)" /> | ||
| <StaticWebAssetEndpoint Remove="@(_BlazorJSEndpointsToRemove)" /> | ||
| <StaticWebAssetEndpoint Include="@(_BlazorJSPublishStaticWebAssetsEndpoint)" /> | ||
| </ItemGroup> | ||
| </Target> | ||
|
|
There was a problem hiding this comment.
This part is confusing me a bit, do we rewrite blazor.js in any way during this whole process? If not, I'm not sure why this is needed at all.
There was a problem hiding this comment.
It's the same issue we have with runtime assets. If we do hard fingerprint during build, the asset to promote for publish has identity without fingerprint (bin/Debug/wwwroot/_framework/blazor.js), but the file on disk has fingerprint (bin/Debug/wwwroot/_framework/blazor.abcd.js) and thus it complains that the file doesn't exist.
This is fixing it by creating an asset that has fingerprint in identity.
Maybe we can do soft fingerprint during build and hard only during publish. Any ideas?
… of defining patterns Aligns with WasmFingerprintAssets and when false it doesn't produce a hard nor soft fingerprint
This PR allows to put hard fingerprint on blazor.js file if
WriteImportMapToHtml=true.It can additionally be controlled with
BlazorFingerprintBlazorJs=false.