Uno.Wasm.Bootstrap/doc/linker-configuration.md

2.6 KiB

uid
UnoWasmBootstrap.Features.LinkerConfig

Linker configuration

The .NET tooling uses the ILLinker, and can be configured using a linker directives file.

The Bootstrapper searches for a file placed in an ItemGroup named LinkerDescriptor. See examples below.

Configuration file (commonly named LinkerConfig.xml)

<linker>
    <assembly fullname="Uno.Wasm.Sample"> <!-- Replace names to reflect your needs -->
        <namespace fullname="Uno.Wasm.Sample" />
    </assembly>

    <assembly fullname="WebAssembly.Bindings" />
</linker>

The documentation for this file can be found here.

Reference in project file

It is also possible to provide the linker file as an embedded resource, which is useful when creating libraries. The linker step will discover those files and apply the configuration.

<!-- For application projects, include this in the .csproj file of your Wasm project -->
<ItemGroup>
    <LinkerDescriptor Include="LinkerConfig.xml" />
</ItemGroup>

<!-- For libraries, you should use this syntax instead -->
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
    <EmbeddedResource Include="LinkerConfig.xml">
        <LogicalName>$(AssemblyName).xml</LogicalName>
    </EmbeddedResource>
</ItemGroup>

The Linker can be disabled completely by setting the WasmShellILLinkerEnabled or PublishTrimmed property to false. This property has no effect when building with AOT enabled.

The .NET SDK configuration options are also supported.

.NET 5 Feature Linker Configuration

The bootstrapper supports the feature switches configuration provided by .NET 5.

By default, some features are linked out as those are not likely to be used in a WebAssembly context:

  • EventSourceSupport
  • EnableUnsafeUTF7Encoding
  • HttpActivityPropagationSupport
  • InvariantGlobalization

If you need to enable any of those features, you can set the following in your csproj first PropertyGroup:

<EventSourceSupport>true</EventSourceSupport>

Setting InvariantGlobalization to true will remove all satellite assemblies from the final package.

LinkerConfig.xml on WebAssembly

When using the Uno Platform solution template, a file named 'LinkerConfig.xml' is available in the folder Platforms\WebAssembly\LinkerConfig.xml.