diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets index ef3a27f424f8aa..0c0df98871681b 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets @@ -197,6 +197,12 @@ Copyright (c) .NET Foundation. All rights reserved. <_WasmEnableWebcil Condition="'$(_WasmEnableWebcil)' == ''">true <_BlazorWebAssemblyJiterpreter>$(BlazorWebAssemblyJiterpreter) <_BlazorWebAssemblyRuntimeOptions>$(BlazorWebAssemblyRuntimeOptions) + + <_BlazorWebAssemblyRuntimeOptions Condition="'$(RunAOTCompilation)' == 'true' and @(BlazorWebAssemblyLazyLoad->Count()) != 0 and !$(_BlazorWebAssemblyRuntimeOptions.Contains('--aot-lazy-assembly-load'))">$([System.String]::Concat('$(_BlazorWebAssemblyRuntimeOptions)', ' --aot-lazy-assembly-load').Trim()) <_WasmInlineBootConfig>$(WasmInlineBootConfig) <_WasmInlineBootConfig Condition="'$(_WasmInlineBootConfig)' == '' and '$(_TargetingNET100OrLater)' == 'true' and '$(WasmBootConfigFileName)' == ''">true <_WasmInlineBootConfig Condition="'$(_WasmInlineBootConfig)' == ''">false diff --git a/src/mono/wasm/Wasm.Build.Tests/LazyLoadingTests.cs b/src/mono/wasm/Wasm.Build.Tests/LazyLoadingTests.cs index 65011962374221..9dc68a80e2a5c0 100644 --- a/src/mono/wasm/Wasm.Build.Tests/LazyLoadingTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/LazyLoadingTests.cs @@ -50,6 +50,28 @@ public async Task LoadLazyAssemblyBeforeItIsNeeded(string lazyLoadingTestExtensi } } + [Fact] + [TestCategory("native-mono")] + public async Task LoadLazyAssemblyWithAOT() + { + // Regression coverage for https://github.com/dotnet/runtime/issues/125794: + // AOT combined with BlazorWebAssemblyLazyLoad must still initialize the runtime + // and lazily load assemblies at runtime. AOT is only supported when publishing + // in Release, so this exercises the publish + AOT + lazy-load combination that + // the Debug build/run tests above do not cover. + Configuration config = Configuration.Release; + ProjectInfo info = CopyTestAsset(config, aot: true, TestAsset.WasmBasicTestApp, "LazyLoadingTestsAOT"); + PublishProject(info, config, new PublishOptions(AOT: true, ExtraMSBuildArgs: "-p:TestLazyLoading=true")); + + RunResult result = await RunForPublishWithWebServer(new BrowserRunOptions( + config, + AOT: true, + TestScenario: "LazyLoadingTest" + )); + + Assert.True(result.TestOutput.Any(m => m.Contains("FirstName")), "The lazy loading test didn't emit expected message with JSON"); + } + [Fact] public async Task FailOnMissingLazyAssembly() {