.NET 9 MAUI trimming is documented here: .0.
After going through all the recommendations for trimming what happens if you publish and find that the app is not working 100%? Is there a way to do the equivalent of dotnet publish
for a debug build on your local development machine so you can more easily capture when errors /exceptions are happening?
Interested primarily in the context of developing in Visual Studio on Windows.
Here's an example where it's possible to miss something. Using Json.Net I have a custom JsonConverter where there is an override of the ReadJson
method. This override makes use of Activator.CreateInstance
so is flagged by the compiler with the IL2091
warning. But the DynamicallyAccessedMembers
that would normally be added to remove the warning cannot be added because it causes the method definition to differ from the base. The only choice is to disable the warning, try to make sure the needed types are preserved, and verify with testing at runtime.
It's the "testing at runtime" cycle that I'm trying to improve by getting runtime diagnostics that can help point out what Type is missing.
.NET 9 MAUI trimming is documented here: https://learn.microsoft/en-us/dotnet/maui/deployment/trimming?view=net-maui-9.0.
After going through all the recommendations for trimming what happens if you publish and find that the app is not working 100%? Is there a way to do the equivalent of dotnet publish
for a debug build on your local development machine so you can more easily capture when errors /exceptions are happening?
Interested primarily in the context of developing in Visual Studio on Windows.
Here's an example where it's possible to miss something. Using Json.Net I have a custom JsonConverter where there is an override of the ReadJson
method. This override makes use of Activator.CreateInstance
so is flagged by the compiler with the IL2091
warning. But the DynamicallyAccessedMembers
that would normally be added to remove the warning cannot be added because it causes the method definition to differ from the base. The only choice is to disable the warning, try to make sure the needed types are preserved, and verify with testing at runtime.
It's the "testing at runtime" cycle that I'm trying to improve by getting runtime diagnostics that can help point out what Type is missing.
Share edited Mar 4 at 18:19 DennisWelu asked Mar 3 at 21:43 DennisWeluDennisWelu 85815 silver badges28 bronze badges 5 |1 Answer
Reset to default 0Temporarily add <PublishTrimmed>true</PublishTrimmed>
to your csproj.
Then you can at least do a local build and skip the need to publish and deploy through Test Flight etc. Even though the Trim a .Net MAUI app documentation says
you temporarily can set it true
to force the issue on local Release builds.
I did not have any success catching exceptions locally or getting nice logging in the Output window. Even adding symbol generation and disabling optimizations in the Release configuration would not help. Still had to rely on exceptions logged to the integrated Application Insights service. Maybe will get that figured out and then will expand further on this partial answer.
full
in the project. I'm trying to do the "thorough testing" now and looking for tips to speed up that build and diagnostic process for observed issues. – DennisWelu Commented Mar 4 at 18:24Debug
andRelease
, so that you can try different combinations of settings. There might be a sweet spot between those two, that speeds up deployment (compared to Release), but includesTrimming
and perhaps some other Release settings. – ToolmakerSteve Commented Mar 9 at 0:30