News

Mono Linker Tool Now Reduces Size of .NET Core Apps

Microsoft is building on top of the Mono platform's handy Linker tool to turn its code-shrinking powers loose on reducing the size of .NET Core apps.

Mono -- an open source implementation of Microsoft's .NET Framework -- has an IL Linker for slimming down code projects.

"The linker is a tool one can use to only ship the minimal possible IL code and metadata that a set of programs might require to run as opposed to the full libraries," the project's GitHub site says. "It is used by the various Xamarin products to extract only the bits of code that are needed to run an application on Android, iOS and other platforms."

That has been modified and now also exists on GitHub as the .NET IL Linker.

"The .NET team has built a linker to reduce the size of .NET Core applications," the project states. "It is built on top of the excellent and battle-tested mono linker. The Xamarin tools also use this linker.

"In trivial cases, the linker can reduce the size of applications by 50 percent. The size wins may be more favorable or more moderate for larger applications. The linker removes code in your application and dependent libraries that are not reached by any code paths. It is effectively an application-specific dead code analysis."

Microsoft's Scott Hanselman put the tool through its paces in updating a 15-year-old .NET 1.1 application and realized different amounts of code shrinkage.

"You can see in some places where there's no size decrease," Hanselman said. "That's because I'm using those assemblies completely. Some see a 100 percent decrease -- they've been removed entirely -- because I'm not using the Registry, for example. And some see a fractional decrease because I'm using some methods but not others."

Microsoft has listed the following caveats for using the experimental tool:

  • Currently only supports publishing self-contained applications. It will fail unless you specify a runtime ID.
  • It is currently an experimental feature. We intend to productize it in a subsequent .NET Core release.
  • Linking only happens during publish, and therefore the linked app needs to be tested after publish, not just after build.
  • The linker can and will break some apps that use reflection. See Using IL Linker Advanced Features for more information about managing reflection usage.

The new experimental tool was released to the community to open it up for experimentation and solicit feedback to improve it. Specifically, Microsoft said it's looking for feedback on topics such as:

  • Linker throughput.
  • Cases where the linker can be more aggressive.
  • Cases where the link is too aggressive and causes applications to fail at runtime.
  • The linker provided an excellent result for a large application

Feedback can be provided by opening issues at either mono/linker or dotnet/core or via e-mail to [email protected].

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube