core icon indicating copy to clipboard operation
core copied to clipboard

What's new in .NET 7 Preview 2 [WIP]

Open leecow opened this issue 3 years ago • 13 comments

What's new in .NET 7 Preview 2

This issue is for teams to highlight work for the community that will release .NET 7 Preview 1

To add content, use a new conversation entry. The entry should include the team name and feature title as the first line as shown in the template below.

## Team Name: Feature title

[link to the tracking issue or epic item for the work]

Tell the story of the feature and anything the community should pay particular attention 
to be successful using the feature.

Preview 1: https://github.com/dotnet/core/issues/7106 Preview 2: https://github.com/dotnet/core/issues/7107 Preview 3: https://github.com/dotnet/core/issues/7108 Preview 4: https://github.com/dotnet/core/issues/7378 Preview 5: https://github.com/dotnet/core/issues/7441 Preview 6: https://github.com/dotnet/core/issues/7454 Preview 7: https://github.com/dotnet/core/issues/7455

leecow avatar Jan 11 '22 18:01 leecow

Note: This feature has been present since Preview 1 but didn't make it to the Preview 1 blog post, so copying the content here again in order to get it into Preview 2 blog.

Introducing the new Regex Source Generator

https://github.com/dotnet/runtime/issues/44676

Ever wished you had all of the great benefits that come from having a specialized Regex engine that is optimized for your particular pattern, without having to pay the costs of building this engine at runtime? We are excited to announce the new Regex Source Generator which is included in Preview 1. It brings all of the performance benefits from our Compiled engine without the startup cost, and it has additional benefits, like providing a great debugging experience as well as being trimming-friendly. If your pattern is known at compile-time, then the new regex source generator is the way to go.

In order to start using it, you only need to turn the containing type into a partial one, and declare a new partial method with the RegexGenerator attribute that will return the optimized Regex object, and that's it! The source generator will fill the implementation of that method for you, and will get updated automatically as you make changes to your pattern or to the additional options that you pass 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.
    // ..
  }
}

And that's it. Please try it out and let us know if you have any feedback.

joperezr avatar Mar 02 '22 21:03 joperezr

CodeGen

Community PRs (Many thanks to JIT community contributors!!)

From @sandreenko

  • https://github.com/dotnet/runtime/pull/64506

From @SingleAccretion

  • https://github.com/dotnet/runtime/pull/63026
  • https://github.com/dotnet/runtime/pull/63100
  • https://github.com/dotnet/runtime/pull/63251
  • https://github.com/dotnet/runtime/pull/63268
  • https://github.com/dotnet/runtime/pull/63447
  • https://github.com/dotnet/runtime/pull/63462
  • https://github.com/dotnet/runtime/pull/63539
  • https://github.com/dotnet/runtime/pull/63845
  • https://github.com/dotnet/runtime/pull/63903
  • https://github.com/dotnet/runtime/pull/63957
  • https://github.com/dotnet/runtime/pull/64012
  • https://github.com/dotnet/runtime/pull/64106
  • https://github.com/dotnet/runtime/pull/64110
  • https://github.com/dotnet/runtime/pull/64122
  • https://github.com/dotnet/runtime/pull/64230
  • https://github.com/dotnet/runtime/pull/64378
  • https://github.com/dotnet/runtime/pull/64498
  • https://github.com/dotnet/runtime/pull/64501
  • https://github.com/dotnet/runtime/pull/64607
  • https://github.com/dotnet/runtime/pull/64701
  • https://github.com/dotnet/runtime/pull/64826
  • https://github.com/dotnet/runtime/pull/64855
  • https://github.com/dotnet/runtime/pull/64882
  • https://github.com/dotnet/runtime/pull/65079

From @Wraith2

  • Recognize BLSR in "x & (x-1)" https://github.com/dotnet/runtime/pull/63545
  • https://github.com/dotnet/runtime/pull/64350

Dynamic PGO

  • https://github.com/dotnet/runtime/pull/63720

Arm64

  • https://github.com/dotnet/runtime/pull/64481
  • https://github.com/dotnet/runtime/pull/64857
  • https://github.com/dotnet/runtime/pull/64864
  • https://github.com/dotnet/runtime/pull/62933
  • https://github.com/dotnet/runtime/pull/65153
  • https://github.com/dotnet/runtime/pull/64740
  • Biggen GC Gen0 for Apple M1 https://github.com/dotnet/runtime/pull/64576
  • Optimize full memory barriers around volatile reads/writes https://github.com/dotnet/runtime/pull/64354
  • https://github.com/dotnet/runtime/pull/64016

General Optimizations

  • Security: https://github.com/dotnet/runtime/pull/63763
  • Testing: https://github.com/dotnet/runtime/pull/64119

JulieLeeMSFT avatar Mar 03 '22 00:03 JulieLeeMSFT

In preview 2 we fixed the following logging source generator failures with various syntax issues:

  • [x] https://github.com/dotnet/runtime/issues/64310
  • [x] https://github.com/dotnet/runtime/issues/62644
  • [x] https://github.com/dotnet/runtime/issues/60968
  • [x] https://github.com/dotnet/runtime/issues/61814
  • [x] https://github.com/dotnet/runtime/issues/58550

maryamariyan avatar Mar 03 '22 18:03 maryamariyan

Observability

  • https://github.com/dotnet/runtime/issues/63648
static Meter s_meter = new Meter("MyLibrary.Queues", "1.0.0");
static UpDownCounter<int> s_queueSize = s_meter.CreateUpDownCounter<int>("Queue-Size");
static ObservableUpDownCounter<int> s_pullQueueSize = s_meter.CreateObservableUpDownCounter<int>("Queue-Size", () => s_pullQueueSize);

...

s_queueSize.Add(10);
s_queueSize.Add(-2);

tarekgh avatar Mar 04 '22 00:03 tarekgh

The PR for blog post; will remain open until Monday 3/14 noon (PST) Create dotnet-7-preview-2.md · Pull Request #784 · microsoft/dotnet-blog (github.com)

The plan is to work on the content in the PR until noon (PST) on Monday 3/14. After that the content will be copied over to the blog and we can make any last minute changes if needed there.

AngelosP avatar Mar 04 '22 01:03 AngelosP

SDK Improvements

dotnet new syntax and tab-completion

https://github.com/dotnet/templating/issues/2191

For 7.0.100-preview2, the dotnet new command has been given a more consistent and intuitive interface for many of the subcommands that users already use. In addition, support for tab-completion of template options and arguments has been massively updated, now giving rapid feedback on valid arguments and options as the user types.

Here's the new help output as an example:

❯ 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 Names

Specifically, all of the commands in this help output no longer have the -- prefix that they do today. This is more in line with what users expect from subcommands in a CLI application. The old versions (--install, etc) are still available to prevent breaking user scripts, but we hope to add obsoletion warnings to those commands in the future to encourage migration.

Tab Completion

The dotnet CLI has supported tab completion for quite a while on popular shells like PowerShell, bash, zsh, and fish (instructions for enabling that can be found here). It's up to individual dotnet commands to implement meaningful completions, however. For .NET 7, the new command learned how to provide tab completion for

  • 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        winformscontrollib   --help               uninstall
globaljson           proto                viewimports          winformslib          -?                   update
  • template options (the list of template options in the web template)
❯ 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 those template options (choice values on an choice template argument)
❯ dotnet new blazorserver --auth Individual
Individual     IndividualB2C  MultiOrg       None           SingleOrg      Windows

There are a few known gaps in completion - for example, --language doesn't suggest installed language values.

Future work

In future previews we plan to continue filling gaps left by this transition, as well as make enabling completions either automatic or as simple as a single command that the user can execute. We hope that this will make improvements in tab-completion across the entire dotnet CLI more broadly used by the community!

What's next

dotnet new users - go enable tab completion and try it for your templating use! Template authors - try out tab completion for the options on your templates and make sure you're delivering the experiences you want your users to have. Everyone - raise any issues you find on the dotnet/templating repo and help us make .NET 7 the best release for dotnet new ever!

baronfel avatar Mar 08 '22 21:03 baronfel

Introducing the new Regex Source Generator

Added it to the draft of the blog post

AngelosP avatar Mar 11 '22 19:03 AngelosP

CodeGen

Added it to the draft of the blog post

AngelosP avatar Mar 11 '22 19:03 AngelosP

SDK Improvements

Added it to the draft of the blog post

AngelosP avatar Mar 11 '22 20:03 AngelosP

Observability

Added it to the draft of the blog post

AngelosP avatar Mar 11 '22 20:03 AngelosP

Logging Source Generator

Added it to the draft of the blog post

AngelosP avatar Mar 11 '22 20:03 AngelosP

NativeAOT Update

We previously announced that we're moving the NativeAOT project out of experimental status and into mainline development in .NET 7. Over the past few months we've been heads down doing the coding to move NativeAOT out of the experimental dotnet/runtimelab repo and into the dotnet/runtime repo. That work has now been completed, but we have yet to add first-class support in the dotnet SDK for publishing projects with NativeAOT. We hope to have that work done shortly, so you can try out NativeAOT with your apps. In the meantime, please try trimming your app and ensure there are no trim warnings. Trimming is a requirement of NativeAOT. If you own any libraries there are also instructions for preparing libraries for trimming.

agocke avatar Mar 14 '22 06:03 agocke

Adding NativeAOT update now...

JeremyLikness avatar Mar 14 '22 22:03 JeremyLikness

.NET 7 GA is available. Closing these pre-release issues.

leecow avatar Jan 24 '23 19:01 leecow