Skip to content

Commit 2b394ae

Browse files
authored
[browser] profiler setup and env variables (#113339)
1 parent 3eb245d commit 2b394ae

23 files changed

+236
-88
lines changed

src/mono/browser/build/BrowserWasmApp.targets

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<WasmEnableSIMD Condition="'$(WasmEnableSIMD)' == ''">$(WasmEnableExceptionHandling)</WasmEnableSIMD>
66
<!-- we are not triggering WasmPerfTracing in Debug automatically, because it would trigger re-link, making dev-loop slow -->
77
<WasmPerfTracing Condition="'$(WasmPerfTracing)' == ''">false</WasmPerfTracing>
8+
<FeaturePerfTracing Condition="'$(FeaturePerfTracing)' == '' and '$(WasmPerfTracing)' == 'true'">true</FeaturePerfTracing>
89
</PropertyGroup>
910

1011
<Import Project="$(WasmCommonTargetsPath)WasmApp.Common.targets" />
@@ -134,6 +135,7 @@
134135
<ItemGroup>
135136
<WasmExtraFilesToDeploy Include="$(WasmMainHTMLPath)" Condition="'$(WasmMainHTMLPath)' != ''" />
136137
<WasmExtraFilesToDeploy Include="$(WasmMainJSPath)" Condition="'$(WasmMainJSPath)' != ''" />
138+
<WasmEnvironmentVariable Include="DOTNET_DiagnosticPorts" Value="$(DiagnosticPorts)" Condition="'$(DiagnosticPorts)' != ''"/>
137139
</ItemGroup>
138140

139141
<RemoveDir Directories="$(WasmAppDir)" />
@@ -151,6 +153,7 @@
151153
RemoteSources="@(WasmRemoteSources)"
152154
ExtraFilesToDeploy="@(WasmExtraFilesToDeploy)"
153155
ExtraConfig="@(WasmExtraConfig)"
156+
EnvVariables="@(WasmEnvironmentVariable)"
154157
NativeAssets="@(WasmNativeAsset)"
155158
DebugLevel="$(WasmDebugLevel)"
156159
IsPublish="$(_WasmIsPublishing)"

src/mono/browser/runtime/cwraps.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ const fn_signatures: SigLine[] = [
130130
[true, "mono_jiterp_end_catch", "void", []],
131131
[true, "mono_interp_pgo_load_table", "number", ["number", "number"]],
132132
[true, "mono_interp_pgo_save_table", "number", ["number", "number"]],
133-
[() => !runtimeHelpers.emscriptenBuildOptions.enablePerfTracing, "mono_jiterp_prof_enter", "void", ["number", "number"]],
134-
[() => !runtimeHelpers.emscriptenBuildOptions.enablePerfTracing, "mono_jiterp_prof_samplepoint", "void", ["number", "number"]],
135-
[() => !runtimeHelpers.emscriptenBuildOptions.enablePerfTracing, "mono_jiterp_prof_leave", "void", ["number", "number"]],
133+
[() => !runtimeHelpers.emscriptenBuildOptions.enablePerfTracing && !runtimeHelpers.emscriptenBuildOptions.enableBrowserProfiler, "mono_jiterp_prof_enter", "void", ["number", "number"]],
134+
[() => !runtimeHelpers.emscriptenBuildOptions.enablePerfTracing && !runtimeHelpers.emscriptenBuildOptions.enableBrowserProfiler, "mono_jiterp_prof_samplepoint", "void", ["number", "number"]],
135+
[() => !runtimeHelpers.emscriptenBuildOptions.enablePerfTracing && !runtimeHelpers.emscriptenBuildOptions.enableBrowserProfiler, "mono_jiterp_prof_leave", "void", ["number", "number"]],
136136

137137
...threading_cwraps,
138138
];

src/mono/browser/runtime/es6/dotnet.es6.lib.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,20 @@ function createWasmImportStubsFrom(collection) {
7878
// we will replace them with the real implementation in replace_linker_placeholders
7979
function injectDependencies() {
8080
createWasmImportStubsFrom(methodIndexByName.mono_wasm_imports);
81-
if (WASM_PERFTRACING) createWasmImportStubsFrom(methodIndexByName.mono_wasm_diagnostic_imports);
8281

8382
#if USE_PTHREADS
8483
createWasmImportStubsFrom(methodIndexByName.mono_wasm_threads_imports);
8584
#endif
8685

8786
DotnetSupportLib["$DOTNET__postset"] = `DOTNET.setup({ ` +
88-
`wasmEnableSIMD: ${WASM_ENABLE_SIMD ? "true" : "false"},` +
89-
`wasmEnableEH: ${WASM_ENABLE_EH ? "true" : "false"},` +
90-
`enablePerfTracing: ${WASM_PERFTRACING ? "true" : "false"}, ` +
91-
`enableAotProfiler: ${ENABLE_AOT_PROFILER ? "true" : "false"}, ` +
92-
`enableBrowserProfiler: ${ENABLE_BROWSER_PROFILER ? "true" : "false"}, ` +
93-
`enablePerfTracing: ${ENABLE_BROWSER_PROFILER ? "true" : "false"}, ` +
94-
`enableLogProfiler: ${ENABLE_LOG_PROFILER ? "true" : "false"}, ` +
95-
`runAOTCompilation: ${RUN_AOT_COMPILATION ? "true" : "false"}, ` +
96-
`wasmEnableThreads: ${USE_PTHREADS ? "true" : "false"}, ` +
87+
`wasmEnableSIMD: ${WASM_ENABLE_SIMD},` +
88+
`wasmEnableEH: ${WASM_ENABLE_EH},` +
89+
`enableAotProfiler: ${ENABLE_AOT_PROFILER}, ` +
90+
`enableBrowserProfiler: ${ENABLE_BROWSER_PROFILER}, ` +
91+
`enableLogProfiler: ${ENABLE_LOG_PROFILER}, ` +
92+
`enablePerfTracing: ${WASM_PERFTRACING}, ` +
93+
`runAOTCompilation: ${RUN_AOT_COMPILATION}, ` +
94+
`wasmEnableThreads: ${!!USE_PTHREADS}, ` +
9795
`gitHash: "${gitHash}", ` +
9896
`});`;
9997

src/mono/browser/runtime/exports-binding.ts

+7-11
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@ export const mono_wasm_threads_imports = !WasmEnableThreads ? [] : [
5050
mono_wasm_warn_about_blocking_wait,
5151
];
5252

53-
export const mono_wasm_diagnostic_imports = [
54-
//event pipe
55-
ds_rt_websocket_create,
56-
ds_rt_websocket_send,
57-
ds_rt_websocket_poll,
58-
ds_rt_websocket_recv,
59-
ds_rt_websocket_close,
60-
];
61-
6253
export const mono_wasm_imports = [
6354
// mini-wasm.c
6455
mono_wasm_schedule_timer,
@@ -101,13 +92,18 @@ export const mono_wasm_imports = [
10192
mono_wasm_resolve_or_reject_promise,
10293
mono_wasm_cancel_promise,
10394
mono_wasm_get_locale_info,
95+
96+
//event pipe
97+
ds_rt_websocket_create,
98+
ds_rt_websocket_send,
99+
ds_rt_websocket_poll,
100+
ds_rt_websocket_recv,
101+
ds_rt_websocket_close,
104102
];
105103

106104
// !!! Keep in sync with exports-linker.ts
107105
const wasmImports: Function[] = [
108106
...mono_wasm_imports,
109-
// diagnostic server exports, when enabled
110-
...mono_wasm_diagnostic_imports,
111107
// threading exports, if threading is enabled
112108
...mono_wasm_threads_imports,
113109
];

src/mono/browser/runtime/exports-linker.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
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-
import { mono_wasm_diagnostic_imports, mono_wasm_imports, mono_wasm_threads_imports } from "./exports-binding";
4+
import { mono_wasm_imports, mono_wasm_threads_imports } from "./exports-binding";
55
import gitHash from "consts:gitHash";
66

77
export function export_linker_indexes_as_code (): string {
88
const indexByName: any = {
99
mono_wasm_imports: {},
1010
mono_wasm_threads_imports: {},
11-
mono_wasm_diagnostic_imports: {},
1211
};
1312
let idx = 0;
1413
for (const wi of mono_wasm_imports) {
@@ -19,10 +18,6 @@ export function export_linker_indexes_as_code (): string {
1918
indexByName.mono_wasm_threads_imports[wi.name] = idx;
2019
idx++;
2120
}
22-
for (const wi of mono_wasm_diagnostic_imports) {
23-
indexByName.mono_wasm_diagnostic_imports[wi.name] = idx;
24-
idx++;
25-
}
2621
return `
2722
var gitHash = "${gitHash}";
2823
var methodIndexByName = ${JSON.stringify(indexByName, null, 2)};

src/mono/browser/runtime/jiterpreter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ function getTraceImports () {
299299
if (nullCheckValidation)
300300
traceImports.push(importDef("notnull", assert_not_null));
301301

302-
if (runtimeHelpers.emscriptenBuildOptions.enablePerfTracing) {
302+
if (runtimeHelpers.emscriptenBuildOptions.enablePerfTracing || runtimeHelpers.emscriptenBuildOptions.enableBrowserProfiler) {
303303
traceImports.push(importDef("prof_enter", getRawCwrap("mono_jiterp_prof_enter")));
304304
traceImports.push(importDef("prof_samplepoint", getRawCwrap("mono_jiterp_prof_samplepoint")));
305305
traceImports.push(importDef("prof_leave", getRawCwrap("mono_jiterp_prof_leave")));

src/mono/browser/runtime/profiler.ts

+8-24
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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-
import type { CharPtr, VoidPtr } from "./types/emscripten";
5-
64
import { ENVIRONMENT_IS_WEB, mono_assert, runtimeHelpers } from "./globals";
75
import { MonoMethod, AOTProfilerOptions, BrowserProfilerOptions, LogProfilerOptions } from "./types/internal";
86
import { profiler_c_functions as cwraps } from "./cwraps";
@@ -46,7 +44,14 @@ export function mono_wasm_init_browser_profiler (options: BrowserProfilerOptions
4644
export function mono_wasm_init_log_profiler (options: LogProfilerOptions): void {
4745
mono_assert(runtimeHelpers.emscriptenBuildOptions.enableLogProfiler, "Log profiler is not enabled, please use <WasmProfilers>log;</WasmProfilers> in your project file.");
4846
mono_assert(options.takeHeapshot, "Log profiler is not enabled, the takeHeapshot method must be defined in LogProfilerOptions.takeHeapshot");
49-
cwraps.mono_wasm_profiler_init_log( (options.configuration || "log:alloc,output=output.mlpd") + `,take-heapshot-method=${options.takeHeapshot}`);
47+
if (!options.configuration) {
48+
options.configuration = "log:alloc,output=output.mlpd";
49+
}
50+
if (options.takeHeapshot) {
51+
cwraps.mono_wasm_profiler_init_log(`${options.configuration},take-heapshot-method=${options.takeHeapshot}`);
52+
} else {
53+
cwraps.mono_wasm_profiler_init_log(options.configuration);
54+
}
5055
}
5156

5257
export const enum MeasuredBlock {
@@ -114,24 +119,3 @@ export function mono_wasm_profiler_record (method: MonoMethod, start: number): v
114119
}
115120
globalThis.performance.measure(methodName, options);
116121
}
117-
118-
/* eslint-disable @typescript-eslint/no-unused-vars */
119-
export function ds_rt_websocket_create (urlPtr :CharPtr):number {
120-
throw new Error("TODO");
121-
}
122-
123-
export function ds_rt_websocket_send (client_socket :number, buffer:VoidPtr, bytes_to_write:number):number {
124-
throw new Error("TODO");
125-
}
126-
127-
export function ds_rt_websocket_poll (client_socket :number):number {
128-
throw new Error("TODO");
129-
}
130-
131-
export function ds_rt_websocket_recv (client_socket :number, buffer:VoidPtr, bytes_to_read:number):number {
132-
throw new Error("TODO");
133-
}
134-
135-
export function ds_rt_websocket_close (client_socket :number):number {
136-
throw new Error("TODO");
137-
}

src/mono/browser/runtime/rollup.config.js

-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const nativeBinDir = process.env.NativeBinDir ? process.env.NativeBinDir.replace
2020
const wasmObjDir = process.env.WasmObjDir ? process.env.WasmObjDir.replace(/"/g, "") : "obj";
2121
const wasmEnableThreads = process.env.WasmEnableThreads === "true" ? true : false;
2222
const wasmEnableSIMD = process.env.WASM_ENABLE_SIMD === "1" ? true : false;
23-
const wasmEnablePerfTracing = process.env.WASM_PERFTRACING === "1" ? true : false;
2423
const wasmEnableExceptionHandling = process.env.WASM_ENABLE_EH === "1" ? true : false;
2524
const wasmEnableJsInteropByValue = process.env.ENABLE_JS_INTEROP_BY_VALUE == "1" ? true : false;
2625
// because of stack walk at src/mono/browser/debugger/BrowserDebugProxy/MonoProxy.cs
@@ -114,7 +113,6 @@ const envConstants = {
114113
configuration,
115114
wasmEnableThreads,
116115
wasmEnableSIMD,
117-
wasmEnablePerfTracing,
118116
wasmEnableExceptionHandling,
119117
gitHash,
120118
wasmEnableJsInteropByValue,

src/mono/browser/runtime/startup.ts

+17-10
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,10 @@ async function ensureUsedWasmFeatures () {
526526
export async function start_runtime () {
527527
try {
528528
const mark = startMeasure();
529+
const environmentVariables = runtimeHelpers.config.environmentVariables || {};
529530
mono_log_debug("Initializing mono runtime");
530-
for (const k in runtimeHelpers.config.environmentVariables) {
531-
const v = runtimeHelpers.config.environmentVariables![k];
531+
for (const k in environmentVariables) {
532+
const v = environmentVariables![k];
532533
if (typeof (v) === "string")
533534
mono_wasm_setenv(k, v);
534535
else
@@ -537,14 +538,20 @@ export async function start_runtime () {
537538
if (runtimeHelpers.config.runtimeOptions)
538539
mono_wasm_set_runtime_options(runtimeHelpers.config.runtimeOptions);
539540

540-
if (runtimeHelpers.config.aotProfilerOptions)
541-
mono_wasm_init_aot_profiler(runtimeHelpers.config.aotProfilerOptions);
542-
543-
if (runtimeHelpers.config.browserProfilerOptions)
544-
mono_wasm_init_browser_profiler(runtimeHelpers.config.browserProfilerOptions);
545-
546-
if (runtimeHelpers.config.logProfilerOptions)
547-
mono_wasm_init_log_profiler(runtimeHelpers.config.logProfilerOptions);
541+
if (runtimeHelpers.emscriptenBuildOptions.enablePerfTracing) {
542+
const diagnosticPorts = "DOTNET_DiagnosticPorts";
543+
const jsReady = "js://ready";
544+
if (!environmentVariables[diagnosticPorts]) {
545+
environmentVariables[diagnosticPorts] = jsReady;
546+
mono_wasm_setenv(diagnosticPorts, jsReady);
547+
}
548+
} else if (runtimeHelpers.emscriptenBuildOptions.enableAotProfiler) {
549+
mono_wasm_init_aot_profiler(runtimeHelpers.config.aotProfilerOptions || {});
550+
} else if (runtimeHelpers.emscriptenBuildOptions.enableBrowserProfiler) {
551+
mono_wasm_init_browser_profiler(runtimeHelpers.config.browserProfilerOptions || {});
552+
} else if (runtimeHelpers.emscriptenBuildOptions.enableLogProfiler) {
553+
mono_wasm_init_log_profiler(runtimeHelpers.config.logProfilerOptions || {});
554+
}
548555

549556
mono_wasm_load_runtime();
550557

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

+2
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ Copyright (c) .NET Foundation. All rights reserved.
378378
Jiterpreter="$(_BlazorWebAssemblyJiterpreter)"
379379
RuntimeOptions="$(_BlazorWebAssemblyRuntimeOptions)"
380380
Extensions="@(WasmBootConfigExtension)"
381+
EnvVariables="@(WasmEnvironmentVariable)"
381382
TargetFrameworkVersion="$(TargetFrameworkVersion)"
382383
ModuleAfterConfigLoaded="@(WasmModuleAfterConfigLoaded)"
383384
ModuleAfterRuntimeReady="@(WasmModuleAfterRuntimeReady)"
@@ -671,6 +672,7 @@ Copyright (c) .NET Foundation. All rights reserved.
671672
StartupMemoryCache="$(_BlazorWebAssemblyStartupMemoryCache)"
672673
Jiterpreter="$(_BlazorWebAssemblyJiterpreter)"
673674
RuntimeOptions="$(_BlazorWebAssemblyRuntimeOptions)"
675+
EnvVariables="@(WasmEnvironmentVariable)"
674676
Extensions="@(WasmBootConfigExtension)"
675677
TargetFrameworkVersion="$(TargetFrameworkVersion)"
676678
ModuleAfterConfigLoaded="@(WasmModuleAfterConfigLoaded)"

src/mono/sample/wasm/Directory.Build.targets

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<Project>
22
<Import Project="../Directory.Build.targets" />
3+
<PropertyGroup>
4+
<WasmPerfTracing Condition="'$(WasmPerfTracing)' == '' and '$(WasmProfilers)' == '' and '$(WasmBuildNative)' != 'false'">true</WasmPerfTracing>
5+
</PropertyGroup>
36
<Import Project="$(BrowserProjectRoot)build\WasmApp.InTree.targets" />
47

58
<PropertyGroup>
@@ -18,7 +21,6 @@
1821
<_ServeMimeTypes>$(_ServeMimeTypes) --mime .cjs=text/javascript</_ServeMimeTypes>
1922
<_ServeMimeTypes>$(_ServeMimeTypes) --mime .js=text/javascript</_ServeMimeTypes>
2023
<_ServeMimeTypes>$(_ServeMimeTypes) --mime .webcil=application/octet-stream</_ServeMimeTypes>
21-
<WasmPerfTracing Condition="'$(WasmPerfTracing)' == '' and '$(WasmProfilers)' == '' and '$(WasmBuildNative)' != 'false'">true</WasmPerfTracing>
2224
</PropertyGroup>
2325

2426
<Target Name="BuildSampleInTree"
@@ -49,6 +51,12 @@
4951
<NestedBuildProperty Include="WasmPerfTracing" />
5052
<NestedBuildProperty Include="WasmEmitSourceMap" />
5153
<NestedBuildProperty Include="WasmEmitSymbolMap" />
54+
<NestedBuildProperty Include="WasmBuildNative" />
55+
<NestedBuildProperty Include="EventSourceSupport" />
56+
<NestedBuildProperty Include="EnableAggressiveTrimming" />
57+
<NestedBuildProperty Include="PublishTrimmed" />
58+
<NestedBuildProperty Include="InvariantTimezone" />
59+
<NestedBuildProperty Include="InvariantGlobalization" />
5260
<NestedBuildPropertyValue Include="/p:%(NestedBuildProperty.Identity)=$(%(NestedBuildProperty.Identity))" Condition="'$(%(NestedBuildProperty.Identity))' != '%(NestedBuildProperty.DefaultValue)'" />
5361
</ItemGroup>
5462
<Exec Command="$(_Dotnet) publish -bl:publish-browser.binlog /p:Configuration=$(Configuration) /p:TargetArchitecture=wasm /p:TargetOS=browser @(NestedBuildPropertyValue, ' ') $(_SampleProject) $(BuildAdditionalArgs)" />

src/mono/sample/wasm/browser-minimal-config/Wasm.Browser.Config.Sample.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<Import Project="..\DefaultBrowserSample.targets" />
3+
<PropertyGroup>
4+
<WasmPerfTracing>false</WasmPerfTracing>
5+
</PropertyGroup>
36
<ItemGroup>
47
<WasmExtraFilesToDeploy Include="main.js" />
58
</ItemGroup>

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

+18-5
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ public DiagnosticsTests(ITestOutputHelper output, SharedBuildPerTestClassFixture
2121
}
2222

2323
[Fact]
24-
public async Task RunSimpleAppWithProfiler()
24+
public async Task RunSimpleAppWithLogProfiler()
2525
{
2626
Configuration config = Configuration.Release;
27-
ProjectInfo info = CopyTestAsset(config, false, TestAsset.WasmBasicTestApp, "ProfilerTest");
28-
// are are linking all 3 profilers, but below we only initialize log profiler and test it
29-
string extraArgs = $"-p:WasmProfilers=\"aot+browser+log\"";
27+
ProjectInfo info = CopyTestAsset(config, false, TestAsset.WasmBasicTestApp, "LogProfilerTest");
28+
29+
string extraArgs = $"-p:WasmProfilers=\"log\"";
3030
BuildProject(info, config, new BuildOptions(ExtraMSBuildArgs: extraArgs, AssertAppBundle: false, WasmPerfTracing: true), isNativeBuild: true);
3131

32-
var result = await RunForBuildWithDotnetRun(new BrowserRunOptions(Configuration: config, TestScenario: "ProfilerTest"));
32+
var result = await RunForBuildWithDotnetRun(new BrowserRunOptions(Configuration: config, TestScenario: "LogProfilerTest"));
3333
Regex regex = new Regex(@"Profile data of size (\d+) bytes");
3434
var match = result.TestOutput
3535
.Select(line => regex.Match(line))
@@ -41,4 +41,17 @@ public async Task RunSimpleAppWithProfiler()
4141
}
4242
Assert.True(fileSize >= 10 * 1024, $"Profile file size is less than 10KB. Actual size: {fileSize} bytes.");
4343
}
44+
45+
[Fact]
46+
public async Task RunSimpleAppWithBrowserProfiler()
47+
{
48+
Configuration config = Configuration.Release;
49+
ProjectInfo info = CopyTestAsset(config, false, TestAsset.WasmBasicTestApp, "BrowserProfilerTest");
50+
51+
string extraArgs = $"-p:WasmProfilers=\"browser\"";
52+
BuildProject(info, config, new BuildOptions(ExtraMSBuildArgs: extraArgs, AssertAppBundle: false, WasmPerfTracing: true), isNativeBuild: true);
53+
54+
var result = await RunForBuildWithDotnetRun(new BrowserRunOptions(Configuration: config, TestScenario: "BrowserProfilerTest"));
55+
Assert.Contains("performance.measure: TestMeaning", result.TestOutput);
56+
}
4457
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Threading.Tasks;
8+
using System.Text.RegularExpressions;
9+
using Xunit.Abstractions;
10+
using Xunit;
11+
12+
#nullable enable
13+
14+
namespace Wasm.Build.Tests;
15+
16+
public class EnvVariablesTests : WasmTemplateTestsBase
17+
{
18+
public EnvVariablesTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext)
19+
: base(output, buildContext)
20+
{
21+
}
22+
23+
[Fact]
24+
public async Task RunSimpleAppEnvVariables()
25+
{
26+
Configuration config = Configuration.Release;
27+
ProjectInfo info = CopyTestAsset(config, false, TestAsset.WasmBasicTestApp, "EnvVariablesTest");
28+
29+
BuildProject(info, config, new BuildOptions(AssertAppBundle: false), isNativeBuild: false);
30+
31+
var result = await RunForBuildWithDotnetRun(new BrowserRunOptions(Configuration: config, TestScenario: "EnvVariablesTest"));
32+
Assert.Contains("foo=bar", result.TestOutput);
33+
Assert.Contains("baz=boo", result.TestOutput);
34+
}
35+
}

src/mono/wasm/build/WasmApp.Common.targets

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
- @(WasmFilesToIncludeInFileSystem) - Files to include in the vfs
9393
- @(WasmNativeAsset) - Native files to be added to `NativeAssets` in the bundle.
9494
95+
- @(WasmEnvironmentVariable) - add environment variables `_framework/blazor.boot.json`
9596
- @(WasmExtraConfig) - json elements to add to `_framework/blazor.boot.json`
9697
Eg. <WasmExtraConfig Include="xxx" Value="true" />
9798

0 commit comments

Comments
 (0)