In this article, I will tell you about how to check the C# version in Visual Studio 2022.
Recently, I came across a real-time project in which I had to migrate the .Net Core older version application to .NET Core 3.1.
In my next blog, I will explain the whole migration process step by step.
But before that, I would like to explain a piece of very basic information that every .NET developer should be aware of.
How to know which C# version is being used in Visual Studio?
I copied one project which was built in Visual Studio 2017 and .NET Core 2.2, then I opened the same project in Visual Studio 2022.
And I see so many errors mentioning similar lines. The error statement was –
Feature 'top-level statements' is not available in C# 8.0. Please use language version 9.0 or greater.
So, first I checked the C# version of the current project.
To check this, right-click on the Project name in solution explorer and select Build->Advanced
You will see the Language version 8.0 as shown in the article.
How to change C# version in your project?
To change the version of C# go to the .csproj file and add the below line.
Complete .csproj file snippet.
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp3.1</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> <LangVersion>10.0</LangVersion> </PropertyGroup> </Project>
I have used C# 10 because I am using Visual Studio 2022, you can change it according to your availability and requirement.
You may check this link for C# Version History – Evolution of .NET