Today, we are pleased to release.NET 7 Preview release 2. The second preview of.NET 7 includes enhancements to the RegEx source generator, progress in moving NativeAOT from experimental to runtime, and a series of significant improvements to the “dotnet New “CLI. These are available for you to grab immediately and start trying out new features, such as:

  • Use the source generator at compile time rather than the slower approach at run time to build a specialized RegEx pattern matching engine.
  • Dotnet New takes advantage of SDK improvements to provide a new simplified TAB completion experience to explore templates and parameters.
  • Don’t cut back and try NativeAOT with your own innovative solutions.

EF7 Preview 2 has also been released and is available on NuGet. You can also read the new features in ASP.NET Core Preview 2.

You can download for Windows, macOS, and Linux. NET 7 Preview 2.

  • Setup program and binaries
  • Container image
  • Linux software package
  • Release notes
  • Known problems
  • GitHub Problem tracker

If you want to try.NET 7 with the Visual Studio family, we recommend that you use the Preview Channel version. .net 7 preview support for Visual Studio for Mac is not yet available, but is coming soon.

Preview 2

Preview 2 now provides the following features.

Introduces a new regular expression source generator

Github.com/dotnet/runt…

Have you ever wished you had all the great benefits of a dedicated regular expression engine optimized for your particular pattern, without the overhead of building that engine at run time?

We are pleased to announce the new regular expression source generator included in preview 1. It brings all the performance benefits of our compilation engine without startup costs, and it has other advantages such as providing a great debugging experience and being prune-friendly. If your pattern is known at compile time, the new regular expression source generator is the way to go.

To get started, you just need to convert the include type to a partial type and declare a new partial method using the RegexGenerator property that will return an optimized Regex object, and that’s it! The source code generator will populate the implementation of this method for you and update it automatically when you change the schema or other options passed in. Here’s an example:

before

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

  public bool Bar(string input)
  {
    bool isMatch = regex.IsMatch(input);
    // ..}}Copy the code

after

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.
    // ..}}Copy the code

That’s it. Please give it a try and let us know if you have any feedback.

The SDK improvements

[Epic] New CLI parser + TAB complete #2191

For **7.0.100-preview2 **, the dotnet new command provides a more consistent and intuitive interface to the many subcommands that users already use. In addition, support for TAB completion of template options and parameters has been greatly updated to provide quick feedback on valid parameters and options as the user types.

Here is an example of the new help output:

❯ dotnet new --help
Description:
  Template Instantiation Commands for .NET CLI.

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

Arguments:
  <template-short-name>  A shortname of the template to create. <template-args> Template specific options to use. Options: -? , -h, --help Show command line help. Commands: install <package> Installs a template package. uninstall <package> Uninstalls a template package. update Checks the currently installed template packagesfor update, and install the updates.
  search <template-name>  Searches for the templates on NuGet.org.
  list <template-name>    Lists templates containing the specified template name. If no name is specified, lists all templates.
Copy the code

New command name

Specifically, all _ commands in this help output no longer have the — prefix as they do now. This is more in line with what users expect from subcommands in CLI applications. Older versions (–install, etc.) can still be used to prevent breaking user scripts, but we hope to add outdated warnings to these commands in the future to encourage migration.

Tab Automatic completion

The dotnet CLI has supported TAB completion on popular shells such as PowerShell, bash, ZSH, and Fish for some time (see How to enable it for instructions. NET CLI Enable TAB completion. However, achieving meaningful completion depends on a separate dotnet command. For.NET 7, the new command learned how to provide Tab completion

  • Available template name (in dotnet new < template-short-name >)
❯ 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      wnformscontrollib   --help     uninstall       
globaljson           proto        viewimports          winformslib          -?      update             

Copy the code
  • Template Options (list of template options in Web templates)
❯ dotnet new web --dry-run
--dry-run                  --language                 --output                   -lang
--exclude-launch-settings  --name                     --type                     -n
--force                    --no-https                 -?                         -o
--framework                --no-restore               -f                         /?
--help                     --no-update-check          -h                         /h
Copy the code
  • The allowed values for these template options (select values on select template parameters)
❯ dotnet new blazorserver --auth Individual
Individual     IndividualB2C  MultiOrg       None           SingleOrg      Windows
Copy the code

There are also known gaps — for example, language does not recommend installing language values.

Future jobs

In future preview releases, we plan to continue filling in the gaps left by this transition and make it either auto-complete or as simple as a single command a user can execute. We hope this will improve the Tab completion functionality of the entire Dotnet CLI and be more widely used by the community!

What’s next

Dotnet New Users – Enable Tab completion and try using templates! Template author – Try Tab completion on your templates and make sure you provide the experience you want your users to have. Everyone – suggest any issues you find in the dotnet/ Templating repository and help us make. NET 7 becomes the best version of Dotnet New!

NativeAOT update

We previously announced that we are moving the NativeAOT project from experimental status to mainline.net 7 development. Over the past few months, we’ve been working hard coding to move NativeAOT out of the experimental dotnet/ Runtimelab repo and into dotnet/ Runtimerepo.

This work is now complete, but we have not yet added support in the Dotnet SDK to publish projects using NativeAOT. We want this done as soon as possible so that you can try Out NativeAOT in your application. In the meantime, try pruning your app and make sure there are no pruning warnings. Pruning is required by NativeAOT. If you have any libraries, refer to the instructions for preparing to trim them.

Targeting .NET 7

For targeting.NET 7, you need to use.net 7 Target Framework Moniker (TFM) in your project file. Such as:

The < TargetFramework > net7.0 < / TargetFramework >

The full set of.NET 7 TFM, including operating system-specific TFM.

  • net7.0
  • Net7.0 – android
  • Net7.0 – ios
  • Net7.0 – maccatalyst
  • Net7.0 – macos
  • Net7.0 – tvos
  • Net7.0 – Windows

We expected it to be easy to upgrade from.NET 6 to.NET 7. Please report any significant changes you find while testing existing applications with.NET 7.

support

.NET 7 is the current version, which means it will receive free support and patches for 18 months from the date of release. It is important to note that all versions are of the same quality. The only difference is the time of support. For more information about.net support policies, see. NET and.net Core official support policies.

A major change

You can find the most recent by reading the major changes documentation in.NET 7. List of major changes to NET 7. It lists major changes by region and version, with links to detailed explanations.

To see what significant Changes have been Proposed but are still under review, follow the question Proposed.net Breaking Changes GitHub.

The roadmap

The.NET version includes products, libraries, runtimes, and tools, and represents collaboration between multiple teams inside and outside Microsoft. You can learn more about these areas by reading the product roadmap:

  • ASP.NET Core 7 and Blazor Roadmap
  • EF 7 Roadmap
  • ML.NET
  • .NET MAUI
  • WinForms
  • WPF
  • NuGet
  • Roslyn
  • Runtime

The end of the

We thank you for all your support and contributions to.NET. Try.net 7 Preview 2 and let us know what you think!