Skip to content

Commit 0ada13f

Browse files
github-actions[bot]maraflewing
authored
[release/10.0] [browser] Expect fingerprint on dotnet.js for preloading (#120746)
Backport of #120694 to release/10.0 In dotnet/sdk#50949 we changed the identity of StaticWebAsset to contain fingerprint (dotnet.native.wasm -> dotnet.native.FP.wasm). This PR accommodates this when checking for dotnet.native.wasm asset from build. The SDK change didn't flown to the runtime yet, and so Wasm.Build.Tests won't test it yet. Fixes dotnet/aspnetcore#64011 /cc @maraf ## Customer Impact - [ ] Customer reported - [x] Found internally [[Select one or both of the boxes. Describe how this issue impacts customers, citing the expected and actual behaviors and scope of the issue. If customer-reported, provide the issue number.]](dotnet/aspnetcore#64011) ## Regression - [x] Yes - [ ] No Introduced in dotnet/sdk#50949 which added a fingerprint to the msbuild item identity ## Testing Manual and automated tests. ## Risk Low. The change are very scoped to target and items used only by preloading. **IMPORTANT**: If this backport is for a servicing release, please verify that: - The PR target branch is `release/X.0-staging`, not `release/X.0`. ## Package authoring no longer needed in .NET 9 **IMPORTANT**: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version. Keep in mind that we still need package authoring in .NET 8 and older versions. --------- Co-authored-by: Marek Fišera <[email protected]> Co-authored-by: Larry Ewing <[email protected]>
1 parent e694305 commit 0ada13f

File tree

3 files changed

+47
-16
lines changed

3 files changed

+47
-16
lines changed

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
<MicrosoftExtensionsLoggingVersion>3.1.7</MicrosoftExtensionsLoggingVersion>
164164
<MicrosoftSymbolStoreVersion>1.0.406601</MicrosoftSymbolStoreVersion>
165165
<!-- sdk version, for testing workloads -->
166-
<SdkVersionForWorkloadTesting>$(MicrosoftDotNetApiCompatTaskVersion)</SdkVersionForWorkloadTesting>
166+
<SdkVersionForWorkloadTesting>10.0.100-rc.2.25501.103</SdkVersionForWorkloadTesting>
167167
<EmsdkPackageVersion>10.0.0-preview.7.25359.101</EmsdkPackageVersion>
168168
<NodePackageVersion>$(runtimewinx64MicrosoftNETCoreRuntimeWasmNodeTransportPackageVersion)</NodePackageVersion>
169169
<!-- The package path for python in src/mono/mono.proj needs to be updated if this changes-->

src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,13 @@ Copyright (c) .NET Foundation. All rights reserved.
514514
</Target>
515515

516516
<Target Name="_AddWasmPreloadBuildProperties" DependsOnTargets="_WasmConfigurePreload;_AddWasmStaticWebAssets" BeforeTargets="GenerateStaticWebAssetsManifest" Condition="'$(_WasmPreloadAssets)' == 'true'">
517+
<PropertyGroup>
518+
<_WasmBootConfigFileNameWithoutExtension>$([System.IO.Path]::GetFileNameWithoutExtension('$(_WasmBootConfigFileName)'))</_WasmBootConfigFileNameWithoutExtension>
519+
<_WasmBootConfigFileExtension>$([System.IO.Path]::GetExtension('$(_WasmBootConfigFileName)'))</_WasmBootConfigFileExtension>
520+
</PropertyGroup>
517521
<ItemGroup>
518-
<_WasmPreloadBuildScriptAsset Include="@(StaticWebAsset)" Condition="'%(AssetKind)' != 'Publish' and '%(FileName)%(Extension)' == '$(_WasmBootConfigFileName)'" />
522+
<_WasmPreloadBuildScriptAsset Include="@(StaticWebAsset)" Condition="'$(_WasmFingerprintAssets)' == 'true' and '$(_WasmFingerprintBootConfig)' == 'true' and '%(AssetKind)' != 'Publish' and '%(FileName)%(Extension)' == '$(_WasmBootConfigFileNameWithoutExtension).%(Fingerprint)$(_WasmBootConfigFileExtension)'" />
523+
<_WasmPreloadBuildScriptAsset Include="@(StaticWebAsset)" Condition="('$(_WasmFingerprintAssets)' != 'true' or '$(_WasmFingerprintBootConfig)' != 'true') and '%(AssetKind)' != 'Publish' and '%(FileName)%(Extension)' == '$(_WasmBootConfigFileName)'" />
519524
</ItemGroup>
520525

521526
<FilterStaticWebAssetEndpoints

src/mono/wasm/Wasm.Build.Tests/PreloadingTests.cs

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System;
45
using System.IO;
56
using System.Linq;
67
using Xunit;
@@ -18,22 +19,26 @@ public PreloadingTests(ITestOutputHelper output, SharedBuildPerTestClassFixture
1819
}
1920

2021
[Theory]
21-
[InlineData(false, false)]
22-
[InlineData(false, true)]
23-
[InlineData(true, false)]
24-
[InlineData(true, true)]
25-
public void PreloadAssets(bool isPublish, bool fingerprintDotnetJs)
22+
[InlineData(false, false, false)]
23+
[InlineData(false, false, true)]
24+
[InlineData(false, true, false)]
25+
[InlineData(false, true, true)]
26+
[InlineData(true, false, false)]
27+
[InlineData(true, false, true)]
28+
[InlineData(true, true, false)]
29+
[InlineData(true, true, true)]
30+
public void PreloadAssets(bool isPublish, bool fingerprintDotnetJs, bool preloadAssets)
2631
{
2732
Configuration config = Configuration.Debug;
2833
ProjectInfo info = CopyTestAsset(config, aot: false, TestAsset.WasmBasicTestApp, "PreloadAssets");
2934

30-
string extraMSBuildArgs = $"-p:WasmFingerprintDotnetJs={fingerprintDotnetJs}";
35+
string extraMSBuildArgs = $"-p:WasmFingerprintDotnetJs={fingerprintDotnetJs.ToString().ToLower()} -p:WasmPreloadAssets={preloadAssets.ToString().ToLower()}";
3136
if (isPublish)
3237
PublishProject(info, config, new PublishOptions(ExtraMSBuildArgs: extraMSBuildArgs), wasmFingerprintDotnetJs: fingerprintDotnetJs);
3338
else
3439
BuildProject(info, config, new BuildOptions(ExtraMSBuildArgs: extraMSBuildArgs), wasmFingerprintDotnetJs: fingerprintDotnetJs);
3540

36-
string? indexHtmlPath = null;
41+
string? indexHtmlPath;
3742
if (isPublish)
3843
{
3944
indexHtmlPath = Path.Combine(
@@ -51,16 +56,37 @@ public void PreloadAssets(bool isPublish, bool fingerprintDotnetJs)
5156
Assert.True(File.Exists(indexHtmlPath));
5257
string indexHtmlContent = File.ReadAllText(indexHtmlPath);
5358

54-
if (fingerprintDotnetJs)
59+
Assert.Equal(preloadAssets ? 1 : 0, CountOccurrences(indexHtmlContent, "rel=\"preload\""));
60+
if (preloadAssets)
5561
{
56-
// Expect to find fingerprinted preload
57-
Assert.Contains("<link href=\"_framework/dotnet", indexHtmlContent);
58-
Assert.DoesNotContain("<link href=\"_framework/dotnet.js\"", indexHtmlContent);
62+
if (fingerprintDotnetJs)
63+
{
64+
// Expect to find fingerprinted preload
65+
Assert.Contains("<link href=\"_framework/dotnet", indexHtmlContent);
66+
Assert.DoesNotContain("<link href=\"_framework/dotnet.js\"", indexHtmlContent);
67+
}
68+
else
69+
{
70+
// Expect to find non-fingerprinted preload
71+
Assert.Contains("<link href=\"_framework/dotnet.js\"", indexHtmlContent);
72+
}
5973
}
60-
else
74+
}
75+
76+
public static int CountOccurrences(string source, string substring)
77+
{
78+
if (string.IsNullOrEmpty(source) || string.IsNullOrEmpty(substring))
79+
return 0;
80+
81+
int count = 0;
82+
int index = 0;
83+
84+
while ((index = source.IndexOf(substring, index, StringComparison.Ordinal)) != -1)
6185
{
62-
// Expect to find non-fingerprinted preload
63-
Assert.Contains("<link href=\"_framework/dotnet.js\"", indexHtmlContent);
86+
count++;
87+
index += substring.Length;
6488
}
89+
90+
return count;
6591
}
6692
}

0 commit comments

Comments
 (0)