Skip to content

Commit 77b1c98

Browse files
authored
Further work on standalone WASM environments (#36390)
1 parent 0d9479a commit 77b1c98

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

aspnetcore/blazor/fundamentals/environments.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,50 @@ On the client for a Blazor Web App, the environment is determined from the serve
3838
<!--Blazor-WebAssembly:{"environmentName":"Development", ...}-->
3939
```
4040

41-
For a standalone Blazor WebAssembly app, set the environment with the `<WasmApplicationEnvironmentName>` property in the app's project file (`.csproj`). The following example sets the `Staging` environment:
41+
For a standalone Blazor WebAssembly app, set the environment with the `<WasmApplicationEnvironmentName>` MSBuild property in the app's project file (`.csproj`). The following example sets the `Staging` environment:
4242

4343
```xml
4444
<WasmApplicationEnvironmentName>Staging</WasmApplicationEnvironmentName>
4545
```
4646

4747
The default environments are `Development` for build and `Production` for publish.
4848

49+
There are several approaches for setting the environment in a standalone Blazor WebAssembly app during build/publish operations and one approach for an app starting or running on the client:
50+
51+
* Set the property value when `dotnet build` or `dotnet publish` is executed. The following example sets the environment to `Staging` when an app is published:
52+
53+
```dotnetcli
54+
dotnet publish -p:WasmApplicationEnvironmentName=Staging
55+
```
56+
57+
* Set the property during build or publish based on the app's configuration in Visual Studio. The following property groups can be used in the app's project file or any publish configuration file (`.pubxml`). Add additional property groups for other build configurations in use.
58+
59+
```xml
60+
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
61+
<WasmApplicationEnvironmentName>Development</WasmApplicationEnvironmentName>
62+
</PropertyGroup>
63+
64+
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
65+
<WasmApplicationEnvironmentName>Production</WasmApplicationEnvironmentName>
66+
</PropertyGroup>
67+
```
68+
69+
* The environment can be set based on the use of a publish profile. In the following example, the first condition sets the environment to `Development` when no publish profile is used (applies to both build and publish operations without a profile), while the second condition covers setting the environment to `Production` when any publish profile is used:
70+
71+
```xml
72+
<PropertyGroup Condition="'$(PublishProfile)' == ''">
73+
<WasmApplicationEnvironmentName>Development</WasmApplicationEnvironmentName>
74+
</PropertyGroup>
75+
76+
<PropertyGroup Condition="'$(PublishProfile)' != ''">
77+
<WasmApplicationEnvironmentName>Production</WasmApplicationEnvironmentName>
78+
</PropertyGroup>
79+
```
80+
81+
* Create a custom server-side web API endpoint. The standalone Blazor WebAssembly app requests its environment from the web API either at app startup or on-demand while it's running. The value should be passed to [`WebAssemblyStartOptions`](https://github.com/dotnet/aspnetcore/blob/main/src/Components/Web.JS/src/Platform/WebAssemblyStartOptions.ts#L7) or with [`withApplicationEnvironment`](https://github.com/dotnet/aspnetcore/blob/main/src/Components/dotnet-runtime-js/dotnet.d.ts#L110).
82+
83+
[!INCLUDE[](~/includes/aspnetcore-repo-ref-source-links.md)]
84+
4985
:::moniker-end
5086

5187
:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

aspnetcore/release-notes/aspnetcore-10/includes/blazor.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ The default environments are:
207207
* `Development` for build.
208208
* `Production` for publish.
209209

210+
For more information, see <xref:blazor/fundamentals/environments#set-the-environment>.
211+
210212
### Boot configuration file inlined
211213

212214
Blazor's boot configuration, which prior to the release of .NET 10 existed in a file named `blazor.boot.json`, has been inlined into the `dotnet.js` script. This only affects developers who are interacting directly with the `blazor.boot.json` file, such as when developers are:

0 commit comments

Comments
 (0)