DEV Community

jsakamoto
jsakamoto

Posted on

Suppress runtime relinking at publishing Blazor WebAssembly apps

Backgounds

After installing ".NET WebAssembly build tools", runtime relinking will be performed automatically whenever you publish Blazor WebAssembly apps in the "Release" configuration.

The install option of ".NET WebAssembly build tools"

Runtime relinking reduces the size of "dotnet.wasm" by trimming unused runtime code.

That size reduction will contribute download speed of Blazor WebAssembly apps.

The size of "dotnet.wasm" before and after installing ".NET WebAssembly build tools"

See also following links for more details.

However, runtime relinking will take a bit long time for publishing.

Of course, this will not matter for almost developers.

But in some rare cases, taking time for runtime relinking annoys developers, particularly when they investigate a problem involved with the publishing process.

Solution

Fortunately, we can suppress runtime relinking manually.

What we have to do is just specifying the "UsingBrowserRuntimeWorkload" MSBuild property to "false".

For example, you can do that with the command line arguments of dotnet publish command.

dotnet publish -c:Release -p:UsingBrowserRuntimeWorkload=false
Enter fullscreen mode Exit fullscreen mode

That command behaves like ".NET WebAssembly build tools" is not installed, so the publishing process finishes faster than the case that runtime relinking is performed.

Compare publishing speed with and without "-p:UsingBrowserRuntimeWorkload=false"

Limitation

Setting the "UsingBrowserRuntimeWorkload" MSBuild property to "false" is available only when the Blazor WebAssembly project doesn't use the "Native Dependency" feature.

If the Blazor WebAssembly project depends on the "Native Dependency" feature, the building and publishing process should be failed.

Top comments (0)