How to Check the Version of C#

which version of c sharp using

Today in this article, we shall see how to check which version of C# your Application is using.


We will see various easy-to-use techniques to verify the version. The below techniques can be used to verify the version on your developer machines or build a machine or cloud server.

You may find the need to check the C# version on the hosted application or server or in a cloud container etc.

We will cover the below aspects in the article,

Please note that as per recent guidelines from Microsoft default version of C# used by the application will be driven by the underlying .NET framework used (This is true for .NET or .NET Core framework used).

Get C# Version using Command line (Windows/Linux/MacOS)

Using any Shell or CLI ex. Visual Studio Command prompt:

Command

csc /langversion:?
which c sharp version net core uses get a version of the C language

C# compiler determines a default language version based on your project’s target framework. The target project when built gets the highest compatible language version by default as per this versioning semantics.

Get C# Version using #Error Directive

One can use the below directive to verify the c# language version.

Just type the below command anywhere in .cs file and mouse hover on it

Command

#error version

what are the correct version numbers for c sharp

Check .NET Core version- SDK and Runtime version Programmatically

Additionally, if you are interested in knowing what version of .NET Core or framework is installed please follow the techniques discussed below,

Command

dotnet --list-sdks

For more details on the commands, please visit the below article,

C# Version using Visual Studio – Option is disabled now

Previously it used to be easy to find C# vesion by navigating the Project- Properties-> Build tab.

However as per new guidelines (explained below).. The visual studio above option is disabled.

As per Microsoft guidelines

Moving forward, however, each version of each framework will have a single supported and default version, and we won’t support arbitrary versions. To reflect this change in support, this commit permanently disables the language version combo box and adds a link to a document explaining the change.

So if using .NET or .NET Core then the framework will always target only a single language version and which will also be a default version.

The default version will be a major version of C#.

So with the above guidelines Visual Studio option to check or update the C# language version is disabled.

Project > Properties > Build > Advanced option is disabled.

Check all supported C# versions to date

Please visit the below Microsoft list,

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version#c-language-version-reference

How to Target specific version

If you need to change or target your application to use a particular C# language version, then there are various approaches to achieve this. Please refer to the below article,



Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.



Leave a Reply

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