How to Check C# Version in Visual Studio?

In this article, we will learn how to check the C# version in Visual Studio 2022. However, this solution will work with all versions of Visual Studio.

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 another blog, the Migration step is explained. Read this blog: 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 the C# version in your project?

Now, suppose your C# version is showing 10 but you want to use an older version or a new version if applicable.

So, to change the version of C# open the .csproj file or right-click on the project name in Visual Studio and select the edit project option. Then, add the below line.

<LangVersion>10.0</LangVersion>

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 the .NET Core version you are using and of course, it depends on the project requirements.

This solution could be similar to other Visual Studio versions as well.

You may check this link for C# Version History – Evolution of .NET

Leave a Comment

RSS
YouTube
YouTube
Instagram