At the beginning of November, there has been the great DotNetConf, were all sorts of cool stuff for my favorite development environment was announced and demonstrated.

Important topics were of course the release of .NET6 as well as Visual Studio 2022, but also all the nice and shiny eco system around it: MAUI (the successor of Xamarin), C# 10 included in the new VS, Entity Frameworks most recent version just as Blazor … A real big pile of Blazor.

.NET 6 release

As the name of the conference says: The biggest part of the party is the release of the newest framework version.
As you will know: There have now been two branches of .NET for a while. The so called “full framework”, which ended in numbers like “4.x” – and .NETCore, which had its latest release as version “3.1”. .NET5, which is a successor of .NETCore should then become the version that also replaces the 4.x branch (hence the naming), but obviously the big shot now followed by .NET6, which is now also the Long-Term-Support (LTS) version.

To support version 6 with the right tailwind, the main Azure services now support .NET6 (Azure App Service, Azure Static Web Apps, Azure Functions, …).

Visual Studio 2022

The most powerful part about VS2022 will be something you won’t find a button for it. VS2022 is now a x64 application itself, which will remove memory-limits and in this way speed things up a lot! And there are also goodies like the solution filter, that enables you to just load the relevant projects in your big solution to improve speed even further.

Besides the improvements of the shell itself, you’ll find some nice features hidden in the options dialog:

  • First two features are at C# > Advanced. There you can enable “Display inline parameter name hints”, which will display the name of the parameter (like a named parameter, but without you having to type it) and “Display inline type hints” for all my friends that do not like the glorious implicit typing of “var” ;-).
  • The other setting is at “Tabs & Windows” and allows you to “Colorize document tabs by project”. Somehow I got the feeling that I’ve already seen this one – but maybe it was a plugin before. As the name indicates, you’ll get tab colors based on the project the file is in, which makes more sense if you like the vertical tab display:

Coding support

The auto-completion with the AI supported intellisense will then be one of the more obvious things when you start working, because everywhere appear code-lines that are sometimes totally off, but sometimes scaringly accurate of what you just thought. Reminds me a LITTLE bit of Githubs Copilot, but this one is more about code-completion and not this text-parsing:

One nice addition with this coding support is the enhanced hints for parameters. Especially for DateTime.Format and Regex – I know some people that will be really happy about that 😁

Sync Namespaces

One new feature I’d expect in a separate tool window and not as prominent as it is currently on the context menu of the solution item itself is “Sync namespaces”. This syncs the namespaces of the various files according to the folder structure.

Value Tracker

Another neat feature is the Value Tracker. You can right click a variable in your debugged code and select “Track Value Source” from the context menu. A new window will appear, that shows you the modifications of this variable. I actually would have hoped to see the intermediate values as well, but a nice step to save the devs some time while hunting issues:

New types of breakpoints

And even the breakpoints have some new features. Introducing temporary breakpoints, which will just get hit once … but WAY cooler is the dependent breakpoint, which will only trigger if ANOTHER breakpoint is hit … how many times have I disabled and re-enabled breakpoints, because I had to wait for my conditional one to trigger first. Great enhancement!

Editor Config

Last feature I’d like to tell you about is the support for the well-known “.editorconfig”-file. You can add one via “Add New Item” > “.editorconfig”, which will create an editorconfig-file with various default values. Trying to open that one in Visual Studio, will popup an editor that allows you to edit the settings in a convenient UI.

Maybe in next release?

Some of the refactorings that were demonstrated, I could not reproduce however in my version (17.0.5). For example an automatic refactoring that would put an await in front of an async line and add the async keyword and Task-Result to the method signature.

C# 10

According to the announcement on .NET6, VS2019 won’t support C#10. So having the latest version is required to use the following syntax-sugar πŸ˜‰

So opening the first time a .NET6 application, you might think that you’ve opened the wrong project. You’ll be greeted by a Program.cs file that reminds you more on something like on Express.JS for Node then on your well know ASP.NET.

Here we already have a whole bunch of new language features at once.

Top Level Statements

You might be missing the boilerplate code around the app initialization like the ConfigureServices method or the Startup class itself. This is caused by the so called “top level statements” were .NET generates the boilerplate code around your code. You don’t have to use this, but this is the default template for a new web app now.

Global usings

Even if you are greeted with a normal “class” file, you’ll recognize the missing usings at the top. This has two reasons: You can now create a file with global usings”. You just need a C#-class, that contains your normal usings and decorate those with the “global” keyword. This can remove some noise from your code-files (but may also lead to confusion, if you don’t name your classes well).

And there is another player in this. Usings like “System” are still missing and do not appear in any existing code file. This is done via “ImplicitUsings” in your project file.

This loads global usings for “System”, “System.Linq” and many more, but varies PER project type.

File scoped namespaces

The third thing that will affect your initial view is the so called “file scoped namespace”. This feature allows you to define a single namespace, without surrounding all your code with braces, just by naming it followed by a colon. Depending on your tab-settings, this might save you important 4 spaces for the customer that requires you to keep your code printable πŸ˜‰

Null parameters

A feature that many people refer to is the parameter-null checking. I found two variants here. Obviously, it should be possible to add two exclamation marks behind a parameter to throw a ArgumentNullException if a null value is passed, but that just brings up a syntax error when I try it. Another inconvenient way is calling ArgumentNullException.ThrowIfNull and pass the parameter, but in the exception message there seems to be a placeholder instead of the failed parameter. So, this seems not to be ready yet.

Record structs

Then there all updates about C# include that record struct thing. Records aren’t new, structs aren’t new … so why is that feature so often mentioned?

I tried that code and you just have to write “public record struct Product(string name, int price);” and it generates for you the properties to use. But that has already been in C#9. So, I read into it and found “it is immutable”, “you can not edit the properties”, “you can not use ref to pass it”.

But trying this out I got away with it:

It lasted a while, till I found this article:
https://anthonygiretti.com/2021/08/03/introducing-c-10-record-struct/

It explains that you’ll either have to implement the properties and replace the “set;” with “init;” OR you ALSO have to mark the record struct as “readonly” to achieve the same effect. NOW it works as intended:

And you’ll have to use the “with”-operator to create a copy of it containing the new assigned value:

to be continued shortly πŸ˜‰

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

I accept that my given data and my IP address is sent to a server in the USA only for the purpose of spam prevention through the Akismet program.More information on Akismet and GDPR.

This site uses Akismet to reduce spam. Learn how your comment data is processed.