This document explains how to reduce the size of published Fazor binaries.
By default, the example projects are configured for cross-platform compatibility and proper functionality:
- OpenGL backend: Used on Linux/macOS
- Direct3D11 backend: Used on Windows (OpenGL is broken on Windows)
- No AI renderer: AI debugging tools are excluded
- No ReadyToRun: Smaller binaries, slightly slower startup
- No debug symbols: Release builds exclude .pdb files
| Configuration | Size (Linux x64) | Size (Windows x64) | Notes |
|---|---|---|---|
| All backends + R2R | ~98 MB | ~98 MB | Original (all features) |
| OpenGL + D3D11, no R2R | ~54 MB | ~54 MB | Default (reliable) |
| OpenGL only, no R2R | ~37 MB | ~37 MB | Smaller but broken on Windows |
Note: D3D11 backend is required for Windows as OpenGL support is unreliable on that platform.
./publish.ps1 -PackAssets -SelfContained -TrimmedThis produces reliable binaries (~54 MB) with:
- Single executable file
- All dependencies included
- Assets embedded
- OpenGL backend (Linux/macOS) + D3D11 backend (Windows)
- Maximum trimming
To enable additional backends or features, you can define compile-time constants:
Add to your .csproj:
<PropertyGroup>
<DefineConstants>$(DefineConstants);INCLUDE_AI_RENDERER</DefineConstants>
</PropertyGroup>Then reference the AI project:
<ItemGroup>
<ProjectReference Include="..\..\src\Sandbox.UI.AI\Sandbox.UI.AI.csproj" />
</ItemGroup>Size impact: +5-10 MB
Add to your .csproj:
<PropertyGroup>
<DefineConstants>$(DefineConstants);INCLUDE_VULKAN_BACKEND</DefineConstants>
</PropertyGroup>Size impact: +15-20 MB
Note: Direct3D11 backend is always included as it's required for Windows support.
To enable R2R for faster startup at the cost of larger binaries, modify your .csproj:
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>Or pass /p:PublishReadyToRun=true to the publish command.
Size impact: +20-25 MB
The default OpenGL backend is optimal for these platforms. No additional configuration needed.
The Direct3D11 backend is always included and automatically used on Windows because OpenGL support is unreliable on that platform. The D3D11Composition backend provides proper transparency support.
If you need even smaller binaries:
- Remove unused controls: Comment out unused controls in
Sandbox.UI/Controls/ - Minimize Assets: Reduce the size of fonts, images, and stylesheets
- Profile trimming: Use
dotnet-illinkanalyzer to identify what can be safely trimmed - Consider framework-dependent deployment: Requires .NET runtime on target machine but much smaller (~5-10 MB)
The build may produce trim analysis warnings. These are mostly safe to ignore as long as the application works correctly. Critical paths have been annotated to preserve necessary code.
OpenGL is not used on Windows by default because it has known issues. The framework automatically uses Direct3D11 instead, which is more reliable and provides better transparency support.
If the application fails to start after trimming, try:
- Set
<TrimMode>partial</TrimMode>instead offull - Add
<PublishTrimmed>false</PublishTrimmed>to disable trimming - Check the trim warnings for hints about what might be missing