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 get right now 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.
- Don't cut yourself trying NativeAOT with your own innovative solution.
EF7 Preview 2 has also been released, available on on NuGet. 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 binaries
- container image
- Linux package
- Release Notes
- Known Issues
- GitHub issue tracker
If you want to try out .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.
Preview 2
The Preview 2 release now provides the following features.
Introduce new regular expression source generator
https://github.com/dotnet/runtime/issues/44676
Have you ever wished for all the great benefits of a dedicated regex engine optimized for your specific pattern without the overhead of building that engine at runtime?
We are happy to announce the new regular expression source generator included in Preview 1. It brings all the performance benefits of our compilation engine without the startup cost, plus it has other benefits like providing a great debugging experience and being trim-friendly. If your patterns are known at compile time, the new regular expression source generator is the way to go.
In order to start using it, you just need to cast the containing type to the partial type , and declare a new partial method with the RegexGenerator attribute that will return the optimized Regex object, that's it! 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. Here is 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);
// ..
}
}
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.
// ..
}
}
That's it. Please try it out and let us know if you have any feedback.
SDK improvements
[[Epic] New CLI parser + tab completion #2191]( https://github.com/dotnet/templating/issues/2191 )
For 7.0.100-preview2 , 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
dotnet CLI has supported tab completion on popular shells like PowerShell, bash, zsh, and fish for a while now (see How to .NET CLI 162389a08b52e4 .NET CLI Enables .NET CLI for instructions on how to enable it) . However, achieving meaningful completion depends on the individual dotnet command . For .NET 7, the new command learned how to provide Tab autocompletion
- 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 (choose values on template parameters)
❯ 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 language values.
Future work
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. Everyone - raise any issues you find in the dotnet/templating repository and help us make .NET 7 the best version of dotnet new !
NativeAOT Updates
We previously announced that we are moving NativeAOT project from experimental status to mainline development for .NET 7. 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 pruning your apply and make sure there are no pruning 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.
support
.NET 7 is the current version of , 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 .
major changes
You can find the latest .NET 7 breaking change list by reading the Breaking Changes in .NET 7 documentation. It lists breaking changes by region and version, with links to detailed instructions.
To see what breaking changes have been proposed but still under review, follow the Proposed .NET Breaking Changes GitHub issue .
route map
.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:
end
We thank you for all your support and contributions to .NET. Please try .NET 7 Preview 2 and let us know what you think!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。