Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,13 @@ Copyright (c) .NET Foundation. All rights reserved.
<Target Name="_ResolveWasmOutputs" DependsOnTargets="ResolveReferences;PrepareResourceNames;ComputeIntermediateSatelliteAssemblies;_ResolveWasmConfiguration;_WasmNativeForBuild">
<ItemGroup>
<_WasmConfigFileCandidates Include="@(StaticWebAsset)" Condition="'%(SourceType)' == 'Discovered'" />
<_DotNetJsItem Include="@(ReferenceCopyLocalPaths)" Condition="('%(FileName)' == 'dotnet' or '%(FileName)' == 'dotnet.native') and '%(Extension)' == '.js'" />

<!-- Remove dotnet.js/wasm from runtime pack, in favor of the relinked ones in @(WasmNativeAsset) -->
<ReferenceCopyLocalPaths Remove="@(ReferenceCopyLocalPaths)"
Condition="@(WasmNativeAsset->Count()) > 0 and ( '%(FileName)' == 'dotnet' or '%(FileName)' == 'dotnet.native' ) and ('%(Extension)' == '.wasm' or '%(Extension)' == '.js')" />
</ItemGroup>
<PropertyGroup>
<_DotNetJsBuildVersion>%(_DotNetJsItem.NuGetPackageVersion)</_DotNetJsBuildVersion>
<_DotNetJsBuildVersion>%(ResolvedRuntimePack.NuGetPackageVersion)</_DotNetJsBuildVersion>
</PropertyGroup>

<ComputeWasmBuildAssets
Expand Down Expand Up @@ -366,12 +365,8 @@ Copyright (c) .NET Foundation. All rights reserved.
Condition="'%(StaticWebAsset.AssetTraitName)' == 'WasmResource' or '%(StaticWebAsset.AssetTraitName)' == 'Culture' or '%(AssetRole)' == 'Alternative'" />
</ItemGroup>

<ItemGroup>
<_DotNetJsItem Include="@(ResolvedFileToPublish)" Condition="'%(ResolvedFileToPublish.DestinationSubPath)' == 'dotnet.js' AND '%(ResolvedFileToPublish.AssetType)' == 'native'" />
</ItemGroup>

<PropertyGroup>
<_DotNetJsVersion>%(_DotNetJsItem.NuGetPackageVersion)</_DotNetJsVersion>
<_DotNetJsVersion>%(ResolvedRuntimePack.NuGetPackageVersion)</_DotNetJsVersion>
</PropertyGroup>

<ComputeWasmPublishAssets
Expand Down
34 changes: 20 additions & 14 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,21 @@ public void DefaultTemplate_NoAOT_WithWorkload(string config)
}

[Theory]
[InlineData("Debug")]
[InlineData("Release")]
public void DefaultTemplate_BuildNative_WithWorkload(string config)
[InlineData("Debug", false)]
[InlineData("Release", false)]
[InlineData("Debug", true)]
[InlineData("Release", true)]
public void DefaultTemplate_BuildNative_WithWorkload(string config, bool expectFingerprintOnDotnetJs)
{
string id = $"blz_buildandbuildnative_{config}_{Path.GetRandomFileName()}";

CreateBlazorWasmTemplateProject(id);

BlazorBuild(new BlazorBuildOptions(id, config, NativeFilesType.Relinked), "/p:WasmBuildNative=true");
BlazorBuild(
new BlazorBuildOptions(id, config, NativeFilesType.Relinked, ExpectFingerprintOnDotnetJs: expectFingerprintOnDotnetJs),
"/p:WasmBuildNative=true",
(expectFingerprintOnDotnetJs ? " /p:WasmFingerprintDotnetJs=true" : string.Empty)
);
}

// Disabling for now - publish folder can have more than one dotnet*hash*js, and not sure
Expand All @@ -83,18 +89,18 @@ public void DefaultTemplate_BuildNative_WithWorkload(string config)
//[InlineData("Release")]
//public void DefaultTemplate_AOT_OnlyWithPublishCommandLine_Then_PublishNoAOT(string config)
//{
//string id = $"blz_aot_pub_{config}";
//CreateBlazorWasmTemplateProject(id);
//string id = $"blz_aot_pub_{config}";
//CreateBlazorWasmTemplateProject(id);

//// No relinking, no AOT
//BlazorBuild(new BlazorBuildOptions(id, config, NativeFilesType.FromRuntimePack);
//// No relinking, no AOT
//BlazorBuild(new BlazorBuildOptions(id, config, NativeFilesType.FromRuntimePack);

//// AOT=true only for the publish command line, similar to what
//// would happen when setting it in Publish dialog for VS
//BlazorPublish(new BlazorBuildOptions(id, config, expectedFileType: NativeFilesType.AOT, "-p:RunAOTCompilation=true");
//// AOT=true only for the publish command line, similar to what
//// would happen when setting it in Publish dialog for VS
//BlazorPublish(new BlazorBuildOptions(id, config, expectedFileType: NativeFilesType.AOT, "-p:RunAOTCompilation=true");

//// publish again, no AOT
//BlazorPublish(new BlazorBuildOptions(id, config, NativeFilesType.Relinked);
//// publish again, no AOT
//BlazorPublish(new BlazorBuildOptions(id, config, NativeFilesType.Relinked);
//}

[Theory]
Expand Down Expand Up @@ -212,7 +218,7 @@ public void BugRegression_60479_WithRazorClassLib()
string razorClassLibraryFileName = UseWebcil ? $"RazorClassLibrary{WebcilInWasmExtension}" : "RazorClassLibrary.dll";
AddItemsPropertiesToProject(wasmProjectFile, extraItems: @$"
<ProjectReference Include=""..\\RazorClassLibrary\\RazorClassLibrary.csproj"" />
<BlazorWebAssemblyLazyLoad Include=""{ razorClassLibraryFileName }"" />
<BlazorWebAssemblyLazyLoad Include=""{razorClassLibraryFileName}"" />
");

_projectDir = wasmProjectDir;
Expand Down
28 changes: 20 additions & 8 deletions src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,8 @@ public string CreateBlazorWasmTemplateProject(string id)
AssertBlazorBundle(options.Config,
isPublish: false,
dotnetWasmFromRuntimePack: options.ExpectedFileType == NativeFilesType.FromRuntimePack,
targetFramework: options.TargetFramework);
targetFramework: options.TargetFramework,
expectFingerprintOnDotnetJs: options.ExpectFingerprintOnDotnetJs);

return res;
}
Expand All @@ -565,7 +566,8 @@ public string CreateBlazorWasmTemplateProject(string id)
AssertBlazorBundle(options.Config,
isPublish: true,
dotnetWasmFromRuntimePack: options.ExpectedFileType == NativeFilesType.FromRuntimePack,
targetFramework: options.TargetFramework);
targetFramework: options.TargetFramework,
expectFingerprintOnDotnetJs: options.ExpectFingerprintOnDotnetJs);

if (options.ExpectedFileType == NativeFilesType.AOT)
{
Expand Down Expand Up @@ -824,7 +826,7 @@ protected static void AssertFile(string file0, string file1, string? label = nul
return result;
}

protected void AssertBlazorBundle(string config, bool isPublish, bool dotnetWasmFromRuntimePack, string targetFramework = DefaultTargetFrameworkForBlazor, string? binFrameworkDir = null, bool expectFingerprinting = false)
protected void AssertBlazorBundle(string config, bool isPublish, bool dotnetWasmFromRuntimePack, string targetFramework = DefaultTargetFrameworkForBlazor, string? binFrameworkDir = null, bool expectFingerprintOnDotnetJs = false)
{
binFrameworkDir ??= FindBlazorBinFrameworkDir(config, isPublish, targetFramework);

Expand Down Expand Up @@ -856,12 +858,21 @@ void AssertFileExists(string fileName)
Assert.True(File.Exists(absolutePath), $"Expected to find '{absolutePath}'");
}

string versionHashRegex = @"\d.0.\d?(-[a-z]+(\.\d\.\d+\.\d)?)?\.([a-zA-Z0-9])+";
string versionHashRegex = @"\.(?<version>.+)\.(?<hash>[a-zA-Z0-9]+)\.";

Assert.Collection(
dotnetJsEntries.OrderBy(f => f),
item => { Assert.Equal(expectFingerprinting ? $"dotnet\\.{versionHashRegex}\\.js" : "dotnet.js", item); AssertFileExists(item); },
item => { Assert.Matches($"dotnet\\.native\\.{versionHashRegex}\\.js", item); AssertFileExists(item); },
item => { Assert.Matches($"dotnet\\.runtime\\.{versionHashRegex}\\.js", item); AssertFileExists(item); }
item =>
{
if (expectFingerprintOnDotnetJs)
Assert.Matches($"dotnet{versionHashRegex}js", item);
else
Assert.Equal("dotnet.js", item);

AssertFileExists(item);
},
item => { Assert.Matches($"dotnet\\.native{versionHashRegex}js", item); AssertFileExists(item); },
item => { Assert.Matches($"dotnet\\.runtime{versionHashRegex}js", item); AssertFileExists(item); }
);
}
}
Expand Down Expand Up @@ -1290,7 +1301,8 @@ public record BlazorBuildOptions
NativeFilesType ExpectedFileType,
string TargetFramework = BuildTestBase.DefaultTargetFrameworkForBlazor,
bool WarnAsError = true,
bool ExpectRelinkDirWhenPublishing = false
bool ExpectRelinkDirWhenPublishing = false,
bool ExpectFingerprintOnDotnetJs = false
);

public enum GlobalizationMode
Expand Down