trimming
A publishing option that removes code the trimmer can prove is unused, making a self-contained app or image smaller.
Trimming can silently remove code used through reflection and break the app at run time.
In more detail
It works by analysing which types and members the app can reach from its entry point. Code reached only through reflection or dynamic discovery can be removed wrongly, so read the trim warnings, run the published app and test reflection-heavy features before enabling it.
Example
dotnet publish -c Release -p:PublishTrimmed=trueRelated terms
- self-contained deployment — Publishing an app together with its own copy of the .NET runtime, so the host needs no .NET installed.
- reflection — Code inspecting types, properties and methods at run time instead of knowing them at compile time.
- dotnet publish — The dotnet command that compiles an app and gathers everything needed to run it into a folder or container image, ready to deploy.
Taught in
- OpenTelemetry, Container Publishing and Trimming — Modern .NET Core, C# & Enterprise Microservices