In .NET 8, Blazor projects now have a way to pass additional configuration options to the runtime, including setting environment variables before Mono starts.
The way to do it depends on whether you're using a blazorwasm
template, or the new blazor
(unified Server/Client project)
If you created a blazorwasm
project from the default template, in wwwroot/index.html
replace this:
<body>
<div id="app">
...
</div>
<div id="blazor-error-ui">
...
</div>
<script src="_framework/blazor.webassembly.js"></script>
</body>
with this
<body>
<div id="app">
...
</div>
<div id="blazor-error-ui">
...
</div>
<script src="_framework/blazor.webassembly.js" autostart="false"></script>
<script>
Blazor.start({
configureRuntime: dotnet => {
console.log("configureRuntime");
dotnet.withEnvironmentVariable("MONO_LOG_LEVEL", "debug");
dotnet.withEnvironmentVariable("MONO_LOG_MASK", "all");
}
});
</script></body>
If you created a blazor
project from the default template with Auto or WebAssembly interactivitiy, in the server project
in App.razor
replace this:
<body>
<Routes />
<script src="_framework/blazor.web.js"></script>
</body>
with this
<body>
<Routes />
<script src="_framework/blazor.web.js" autostart="false"></script>
<script>
Blazor.start({
webAssembly: {
configureRuntime: dotnet => {
console.log("in configureRuntime");
dotnet.withEnvironmentVariable("MONO_LOG_LEVEL", "debug");
dotnet.withEnvironmentVariable("MONO_LOG_MASK", "all");
}
}
});
</script>
</body>