Open rocksdanister opened 11 months ago
Early test shows upto 50% reduction (50mb -> 25mb) with the following Default.md file:
<!--<Assembly Name="*Application*" Dynamic="Required All" />-->
<!-- .NET Native fix -->
<Assembly Dynamic="Required All" Name="NLog"/>
<Assembly Dynamic="Required All" Name="Microsoft.Extensions.DependencyInjection"/>
<Assembly Dynamic="Required All" Name="Microsoft.Extensions.Options"/>
<Assembly Dynamic="Required All" Name="Microsoft.Extensions.Logging"/>
<Assembly Dynamic="Required All" Name="Microsoft.Extensions.Http"/>
Problem is serializers returning null due to reflection, will need to rewrite using source generator: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation
I was suggested to use System.Text.Json 8.0 Preview 1
for better source generators.
Sample:
[JsonSourceGenerationOptions(PropertyNameCaseInsensitive = true)]
[JsonSerializable(typeof(AirQuality), GenerationMode = JsonSourceGenerationMode.Metadata)]
internal partial class MyJsonContext : JsonSerializerContext
{
}
..
await JsonSerializer.DeserializeAsync(stream, MyJsonContext.Default.AirQuality);
From Default.rd.xml remove:
<Assembly Name="Application" Dynamic="Required All" />
Have to rewrite using DI source generator: https://github.com/CommunityToolkit/Labs-Windows/discussions/463
Other MSBuild options you can set in your .csproj/.props to save size:
First one should save ~8% of binary size Second one can save a few hundred KBs (this is all per CPU arch)