.NET 7 builds on top of .NET 6, which includes a unified set of base libraries, runtime, and SDK, a simplified development experience, and higher developer productivity. Major areas of focus for .NET 7 include improved support for cloud native scenarios, tools to make it easier to upgrade legacy projects, and simplifying the developer experience by making it easier to work with containers.
Several improvements have been made in .NET 7 Previews 1, 2 and 3, some of them we will cover in some demos.
- Nullable annotations for Microsoft.Extensions
- JIT compiler optimizations
- New APIs
- Support for more hot reload scenarios
- Specialized RegEx pattern matching engine
- Improved tab completion capabilities to explore templates and parameters when using dotnet new
- App Trimming due to NativeAOT (Native Ahead of Time compilation) support.
- Native AOT
- Default GC regions
- ASP.NET Core startup time improvements
Download and install latest version of .NET 7.
| Latest Version | Download |
|---|---|
| 7.0.100-preview.3 | https://dotnet.microsoft.com/en-us/download/dotnet/7.0 |
Create a new project
Configure your new project
Select .NET 7.0 (Preview) and click Create
Program.cs looks the same as .NET 6.0
But the .csproj has a new TargetFramework
By default, if you select .NET 7.0 (Preview,) your project will be ready to take advantage of the .NET 7.0 features, if you are upgrading a .NET 6 project to .NET 7, all you have to do is to change the TargetFramework value from net6.0 to .net7.0 as shown below.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>The available options for the TargetFramework Monicker are shown below:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<!--Available TargetFramework values
net7.0
net7.0-android
net7.0-ios
net7.0-maccatalyst
net7.0-macos
net7.0-tvos
net7.0-windows-->
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>This new attribute allows you to specify what kind of data a string represents, for example Regex, JSON, or a DateTime. This will be use to support more syntax highlighting and colorization options.
Before
After
Note
Resource dotnet/runtime#62505
Hot Reload now has support for the following edit operations in C# for Blazor WebAssembly and .NET for iOS and Android
- Adding static lambdas to existing methods
- Adding lambdas that capture this to existing methods that already have at least one lambda that captures this
- Adding new static or non-virtual instance methods to existing classes
- Adding new static fields to existing classes
- Adding new classes
As of .NET 7 Preview 1 the following Microsoft.Extensions libraries have been annotated for Nullability:
- Microsoft.Extensions.DependencyInjection.Abstractions
- Microsoft.Extensions.Logging.Abstractions
- Microsoft.Extensions.Primitives
- Microsoft.Extensions.FileSystemGlobbing
- Microsoft.Extensions.DependencyModel
- Microsoft.Extensions.Configuration.Abstractions
- Microsoft.Extensions.FileProviders.Abstractions
- Microsoft.Extensions.FileProviders.Physical
- Microsoft.Extensions.Configuration
- Microsoft.Extensions.Configuration.Binder
- Microsoft.Extensions.Configuration.CommandLine
- Microsoft.Extensions.Configuration.EnvironmentVariables
- Microsoft.Extensions.Configuration.FileExtensions
- Microsoft.Extensions.Configuration.Ini
- Microsoft.Extensions.Configuration.Json
By the time .NET 7 is released, all Microsoft.Extensions libraries are planned to be annotaded for Nullability.
The dotnet new command has been given a more consistent and intuitive interface for many of the subcommands that users already use. Support for tab completion of template options and arguments has been enhanced, now giving rapid feedback on valid arguments and options as the user types.
dotnet new -help
carl ❯❯ 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.
- Resource 1: https://devblogs.microsoft.com/dotnet/announcing-dotnet-7-preview-2/
- Resource 2: dotnet/templating#2191
| Resource Title | Url |
|---|---|
| .NET 7 Downloads | https://dotnet.microsoft.com/en-us/download/dotnet/7.0 |
| ASP.NET Core Roadmap for .NET 7 | dotnet/aspnetcore#39504 |
| Announcing .NET 7 Preview 1 | https://devblogs.microsoft.com/dotnet/announcing-net-7-preview-1/ |
| Announcing .NET 7 Preview 2 – The New, ‘New’ Experience | https://devblogs.microsoft.com/dotnet/announcing-dotnet-7-preview-2/ |
| Announcing .NET 7 Preview 2 | https://devblogs.microsoft.com/dotnet/announcing-dotnet-7-preview-3/ |
| StringSyntaxAttribute | dotnet/runtime#62505 |