DEV Community

Cover image for .NET Celebrates 20 years and brings us a GIFT🎁: New .NET 7 Features Revealed

Posted on • Updated on • Originally published at

.NET Celebrates 20 years and brings us a GIFT🎁: New .NET 7 Features Revealed

Who better person to announce the 20th anniversary of .NET than Bill Gates? Well, that’s how it went at the 2002 VSLive!

It’s amazing! But in case you didn’t know, the .NET framework, according to Stack Overflow survey, has been the most loved framework by developers for the past 3 years.

Yes, the .NET Framework celebrated 20 years since its creation in 2002 and just a couple of days ago, Microsoft has released new features of .NET 7, which is expected to be officially released in November this year. Let’s see what these features are and analyze them!

Improved Regex source generator

The new Regex Source Generator means that you can shave off up to 5x the time spent optimizing patterns from our compiled engine without having to sacrifice any of the associated performance benefits. Additionally, because it operates within a partial class, there is no overhead of compiling-time for instances when users know their pattern at runtime. With this feature, if your pattern can be known at compile-time, then this generator is recommended instead of our traditionally compiler based approach.

All you need to do is set up a partial declaration with an attribute called RegexGenerator which points back to the method that will return an already precompiled regular expression object (with all other features enabled). Our generator will take care of creating that method and updating it as needed according to changes made to either the original string or passed in options (like case sensitivity etc…).

Let’s take a look at the comparison of the Microsoft example:


public class Foo
  public Regex regex = new Regex(@"abc|def", RegexOptions.IgnoreCase);

  public bool Bar(string input)
    bool isMatch = regex.IsMatch(input);
    // ..
Enter fullscreen mode Exit fullscreen mode


public partial class Foo  // <-- Make the class a partial class
   [RegexGenerator(@"abc|def", RegexOptions.IgnoreCase)] // <-- Add the RegexGenerator attribute and pass in your pattern and options

   public static partial Regex MyRegex(); //  <-- Declare the partial method, which will be implemented by the source generator
  public bool Bar(string input)
    bool isMatch = MyRegex().IsMatch(input); // <-- Use the generated engine by invoking the partial method.
    // ..
Enter fullscreen mode Exit fullscreen mode

SDK improvements

For those who work with .NET Framework, using dotnet new will be a much easier task. With major updates such as an improved intuitiveness and an increased speed of tab completion, it would be hard to find anything negative about this change.

If you want to go deeper, here is the original example from Microsoft:

 dotnet new --help
  Template Instantiation Commands for .NET CLI.

  dotnet new [<template-short-name> [<template-args>...]] [options]
  dotnet new [command] [options]

  <template-short-name>  A short name of the template to create.
  <template-args>        Template specific options to use.

  -?, -h, --help  Show command line help.

  install <package>       Installs a template package.
  uninstall <package>     Uninstalls a template package.
  update                  Checks the currently installed template packages for update, and install the updates.
  search <template-name>  Searches for the templates on
  list <template-name>    Lists templates containing the specified template name. If no name is specified, lists all templates.
Enter fullscreen mode Exit fullscreen mode

New command names

Command lines in general were changing — specifically, every command shown in this output will no longer include the -- prefix as it does now. This was done to align with what a user would expect from a subcommand for an app built for command lines.

The old versions of these commands (--install, etc) are still available just in case it breaks scripts but we hope that one day there will be deprecation warnings included to those commands so you can transition over without risk.

Tab key completion

For a long time now, the dotnet command line interface has had support for tab completion on shells such as PowerShell, bash, zsh, and fish. The commands themselves are able to decide what they want to show when given input.

Now in .NET 7, the new command allows quite a lot of functionalities:

 dotnet new angular
angular              grpc                 razor                viewstart            worker               -h
blazorserver         mstest               razorclasslib
web                  wpf                  /?
blazorwasm           mvc                  razorcomponent       webapi               wpfcustomcontrollib  /h
classlib             nugetconfig          react                webapp               wpflib               install
console              nunit                reactredux           webconfig            wpfusercontrollib    list
editorconfig         nunit-test           sln                  winforms             xunit                search
gitignore            page                 tool-manifest        winformscontrollib   --help               uninstall
globaljson           proto                viewimports          winformslib          -?                   update
Enter fullscreen mode Exit fullscreen mode

If you are interested in knowing how to enable it, I recommend you to check the Microsoft’s guide. And likewise, if you want to know all the possibilities of this feature, I recommend you to consult again the original source.

Dynamic PGO improvements

Microsoft has recently introduced a new breakthrough for program optimization. Called the Dynamic PGO, it is designed to make some key changes from the Static PGO we already know about. Where Static PGO requires developers to use special tools separately from training, Dynamic PGO doesn’t require any of that; all you need to do is run the application you are interested in optimizing and then collect data for Microsoft!

Now, according with Andy Ayers in GitHub, the following is added:

Extend ref counting done by local morph so that we can determine
single-def single-use locals.

Add a phase that runs just after local morph that will attempt to
forward single-def single-use local defs to uses when they are in
adjacent statements.

Fix or work around issues uncovered elsewhere:

  • gtFoldExprCompare might fold "identical" volatile subtrees.

  • fgGetStubAddrArg cannot handle complex trees.

  • Some simd/hw operations can lose struct handles.

  • Some calls cannot handle struct local args.

You can check the original pull for more details.


These features are the last ones that have come to light by Microsoft and we will have to see what more features they show us.

As far as we can all see (and as far as Microsoft lets us see), everything is going according to plan and we can expect the official launch of .NET 7 at the end of this year (more specifically in November).

So for the moment, we will be watching for any announcement or news from Microsoft on .NET 7!

Discussion (0)