.NET 7 Inches Closer to NativeAOT in Preview 2

Native ahead-of-time (AOT) compilation -- a much-requested and long-awaited feature for .NET -- is getting closer in the new .NET 7 Preview 2.

NativeAOT (sometimes called "Native AOT" by Microsoft) was deemed so important that a survey conducted a couple years ago indicated its absence was holding back .NET adoption.

Does the lack of officially supported native AOT option prevent you from using .NET more?
[Click on image for larger view.] "Does the lack of officially supported native AOT option prevent you from using .NET more?" (source: Microsoft).

In this week's Preview 2, work continued on the project, which is now in the mainline development stream after previously being labeled "experimental." As part of that, some foundational housekeeping had to be done, moving the project from one GitHub repo to another. With that done, polishing up the bits for real-world testing is in order.

"That work has now been completed, but we have yet to add first-class support in the dotnet SDK for publishing projects with NativeAOT," said Angelos Petropoulos, product manager for .NET, in a March 14 announcement of Preview 2. "We hope to have that work done shortly, so you can try out NativeAOT with your apps. In the meantime, please try trimming your app and ensure there are no trim warnings. Trimming is a requirement of NativeAOT. If you own any libraries there are also instructions for preparing libraries for trimming."

The NativeAOT in .NET 7 #61231 GitHub issue shows the initial work being checked off and what's remaining in the first phase:

NativeAOT in .NET 7 Goals
[Click on image for larger view.] NativeAOT in .NET 7 Goals (source: Microsoft).

As far as new features that are available in Preview 2, Microsoft introduced a new Regex Source Generator, which was actually included in Preview 1 but which didn't make the announcement post so Microsoft is detailing it now. Provided by the C# compiler, Source Generators help C# developers inspect user code as it is being compiled and generate on-the-fly C# source files that are added to the user's compilation.

Now, as a GitHub issue explains, Developers can precompile their Regex code for faster startup under certain conditions.

"It brings all of the performance benefits from our compiled engine without the startup cost, and it has additional benefits, like providing a great debugging experience as well as being trimming-friendly," Petropoulos said. "If your pattern is known at compile-time, then the new regex source generator is the way to go."

Other bits of minor functionality were also added, including improvements to tab completion when using the dotnet command-line interface (CLI) commands.

You can read all about that and much more in the What's new in .NET 7 Preview 2 documentation.

What's New for ASP.NET Core in .NET 7 Preview 2
Meanwhile, improvements made to the web-dev component of .NET 7, ASP.NET Core, include:

You can read more about all of those here and in the ASP.NET Core Roadmap for .NET 7.

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus


  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

  • What's New for Python, Java in Visual Studio Code

    Microsoft announced March 2024 updates to its Python and Java extensions for Visual Studio Code, the open source-based, cross-platform code editor that has repeatedly been named the No. 1 tool in major development surveys.

Subscribe on YouTube