1
头图

Today, we're excited to release Preview 2 of .NET 7. 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 experience. These are available for you to grab right away and start trying new features, such as:

  • Use the source generator at compile time instead of the slower method at run time to build a specialized RegEx pattern matching engine.
  • dotnet new leverages SDK improvements to provide a new simplified tab-completion experience to explore templates and parameters.
  • Try NativeAOT with your own innovative solution.

Preview 2

new regular expression source generator

The new regular expression source generator brings more performance benefits of our compilation engine at no additional cost, it also provides a great debugging experience and easy pruning. If your patterns are known at compile time, the new regular expression source generator can help you very well.

You just need to convert the containing type to a partial type and declare a new partial method using the RegexGenerator property that will return the optimized Regex object. The source code generator will populate the implementation of the method for you, and update it automatically when you change the mode or other options passed in.
https://github.com/dotnet/runtime/issues/44676

Before update


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

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

Updated


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.
    // ..
  }
}

▌SDK Improvement

Epic new CLI parser + tab completion #2191

As of 7.0.100-preview 2, the dotnet new command provides a more consistent and intuitive interface to many of the subcommands that users already use. Additionally, support for tab-completion for template options and parameters has been heavily updated, and now provides 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]
  dotnet new [command] [options]

Arguments:
  <template-short-name>  A short name 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 packages for 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.

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 deprecation warnings to these commands in the future to encourage migration.

Tab autocomplete

The dotnet CLI has supported tab completion on popular shells like PowerShell, bash, zsh, and fish for some time (see How to Enable TAB Completion for .NET CLI for instructions on how to enable it). However, achieving meaningful completion depends on individual dotnet commands. For .NET 7, the new command learned how to provide tab completion.

  • Available template names (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           
  • 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

  • Allowed values for these template options (select value on template parameter)

❯ dotnet new blazorserver --auth Individual
Individual     IndividualB2C  MultiOrg       None           SingleOrg      Windows

There are of course some known gaps - for example, --language does not recommend installing the language value.

Future Jobs

In future previews, we plan to continue to fill in the gaps left by this transition and make autocomplete or as simple as a single command a user can execute. We hope this will improve tab completion across the dotnet CLI and be more widely used by the community!

What's next

dotnet new users - enable tab completion and try out templates! Template Authors – Experiment with tab completion on your templates and make sure you deliver the experience you want your users to have. File any issues you find in the dotnet/templating repository and help us make .NET 7 the best version of dotnet new!

NativeAOT Update

We previously announced that we are project from experimental status to mainline development for .NET 7 at 1623d22299269d. For the past few months, we've been diving into coding to move NativeAOT out of the experimental dotnet/runtimelab repo and into the dotnet/runtime repo.

This work is now complete, but we have not yet added support in the dotnet SDK to publish projects using NativeAOT. We hope to get this done as soon as possible so that you can try NativeAOT in your application. Meanwhile, try trimming your apply and make sure there are no trim warnings. Pruning is a requirement of NativeAOT. If you own any library, please refer to for instructions on preparing the library for trimming .

Targeting .NET 7

To target .NET 7, you need to use the .NET 7 Target Framework Moniker (TFM) in your project file. E.g:

<TargetFramework> net7.0 </TargetFramework>

Full suite of .NET 7 TFMs, including OS-specific TFMs.

  • net7.0
  • net7.0-android
  • net7.0-ios
  • net7.0-maccatalyst
  • net7.0-macos
  • net7.0-tvos
  • net7.0-windows
    We hope that upgrading from .NET 6 to .NET 7 should be simple. Please report any breaking changes you find while testing your existing applications with .NET 7.

supports

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

changes

You can find the latest .NET 7 breaking change list by reading the Breaking Changes in .NET 7 document. It lists breaking changes by region and version, with links to detailed descriptions.
To see what breaking changes have been proposed but still under review, follow the Proposed .NET Breaking Changes GitHub issue.

Roadmap

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

use immediately

EF7 Preview 2 has also been released, Available on NuGet as . You can also read 's New in ASP.NET Core Preview 2 . You can download .NET 7 Preview 2 for Windows, macOS, and Linux.

installer and binary
container image
Linux package
Release Notes
known issues
GitHub issue tracker

If you want to try .NET 7 in the Visual Studio family of products, we recommend you use the preview channel build . Visual Studio for Mac support for .NET 7 Preview is not yet available, but will be coming soon.


微软技术栈
418 声望994 粉丝

微软技术生态官方平台。予力众生,成就不凡!微软致力于用技术改变世界,助力企业实现数字化转型。