Level trimming, and so is being released as an experimental feature, that is not yet ready for mainstream adoption. Member-level trimming has more risk than assembly This can have a big effect where only a small subset of an assembly is used – for example, the console application above. NET 5 can take it two levels further and remove types and members that are not used. To assembly-level trim, use the dotnet publish command either without a trim mode, or use CopyUsed in the project file:ĭotnet publish -r win10-圆4 -p:PublishTrimmed=True
SAFE TO REMOVE MONO FRAMEWORK CODE
This is largely transparent to the static analysis, so it needs to either be told about the required types orīe able to detect common dynamism patterns – otherwise it will trim away code that is needed by the application which will result in runtime crashes. For example, Dependency Injection in ASP.NET Core uses reflection to select appropriate constructors. The trimming does a static analysis of the code and therefore can only identify types and members when they are referenced from code. Trimming sounds great, but as with most good things, there is a catch.
The framework assemblies, it doesn’t account for the runtime which is a fixed cost that applies to every app.
The size reductions above are probably better than can be expected for most real apps – the app simply outputs “Hello World!”, so makes minimal usage of most of the assemblies. * As the commercials say, “results not typical”. For example, for a Hello World app ( dotnet new NET 5, we are taking this further, and cracking open the assemblies, and removing the types and members that are not used by the application, further reducing the size. It will then only package those assemblies into the app, thereby reducing the size of the application. Optionally during the publish process, a trim phase occurs which does an exhaustive walk of the code paths identifying the assemblies that are used by the code. It is also sometimes called the “assembly linker”. We first made assembly trimming available as part of. To resolve the size problem, we introduced an option to trim unused assemblies as part of publishing self-contained applications. The downside is the size – it pulls along a complete copy of the runtime & framework. From anĪpplication developer perspective, this means that you know exactly which version of the runtime is being used, and the installation/setup is easier. It doesn’t depend on having the framework separately installed. NET Core supports self-contained deployment – everything needed to run the application is bundled together.