Visual Studio 2022 & .Net 6.0 Features
This article will explain some of great Visual Studio 2022 and .Net 6.0 including C# 10 features which definitely will love by all the developers.
As we know, now visual studio 2022 is out for public use, we can download: https://visualstudio.microsoft.com/downloads/
After download, it will provide you .Net 6.0 and C# 10 features support and you can select that framework/version while you creating new app.
If you just want to use .Net 6.0, not visual studio 2022 then you can download .Net 6.0 runtime or SDK: https://dotnet.microsoft.com/download/dotnet/6.0
Visual Studio 2022 Important Features:
- It is not 64 bit SDK and because of that overall load of any big to big solution, will load very frequently and you should be able to work with your bit project without any delay and easily debug and navigate to various part of your project.
- It improved, search performance throughout the solution/project to find verry quickly as per your search text.
- It build only the modified app not all of them exists inside solution. So think of you have solution with 100 projects and you just made some change into 2 projects and you are building your solution, so in that case it will only build those 2 modified projects.
- As we know, we use visual studio for doing process dump analysis to find the CPU or memory utilization cause and with visual studio 2022, it will do that analysis very fast and also has little bit improvement in finding/navigating to actual problem code base from the analysis result panel.
- Hot reload, where you can make change to your code while your app is in debug mode. So earlier, if our app is in debug mode and we want to make some change then we had to stop the debugging and then make the change and then run(F5) app again to see the change. But with Hot reload feature, it will save our much more time and see the change immediately.
- Demo: When you app is in debug mode, just do change and then click on Hot Reload button to see the latest change.
With above example, if you see when I ran this program, I had first message which is commented in screenshot and same displayed on output window and then on next execution when it hit to debug again, I commented the first message and made new message and then save and click on "Hot Reload icon" and debug to next step, it will new output.
Notes:
- For using Hot Reload, make sure your code is in debug mode, so like before making change, your debug point is there inside your code base and then do change of code, save and then click on hot reload and then use F10 or F5 to debug next line/step to see the new change.
- Intellicode - improvement, suggest entire line while writing code based in your existing program code base and then just press tab and it will give you that line and you do not need to write that manually:
- Code refactoring suggestions: If you keep cursor on any line, it will provide you suggestions to refactor your code at as per intelligence:
- GitHub action, to apply CICD pipeline while publishing code from visual studio to Azure, so while you right click on your app from solution explorer and publish and then choose azure service and you would have option to use Github action CICD and it will automatically setup for your which you can verify by going into Github after setup:
C# 10 important features:
- Single line namespace declaring: To improve line of code we do not require braces { } for namespace body. We can simply add namespace top of the file and it will apply to that file:
- Global using: Now we can define our using list(namespaces) at one place and same will be used across all the files, so we do not need to write using statement with each files:
Demo: If I want to use above User class inside program.cs file, then I have import User namespace and similarly if User class will be used inside multiples files/classes then I will have to import with all such files/classes, so instead of doing that, I can create separate class let say(GlobalUsing.cs) and there I can import all such namespace as global which will automatically apply to all the files/class inside that project:
One other thing, if you see with above example, we are using "Console.WriteLine()" but we have not import "using system" namespace anywhere and this is because "ImplicitUsings" setting is enabled on app level by default:
- Record type with class and struct: Struct properties are mutable by default, while record class properties are immutable. However, you can declare a readonly record struct, which is immutable and matches the record class type:
So, with above example, if you see when I am trying to update record class name value then it is throwing compilation error.
Below screenshot, how I am calling this class and method from program.cs:
More to come soon....
Categories/Tags: Visual Studio 2022~VS 2022~.Net 6~C# 10