How To Get A Version Of The C# Language
Today in this article, we shall see how to get a version of the C# language your application is using Command line and using .NET code.
You may find the need to check the C# version on the hosted application or server or in a cloud container etc.
Especially if you are using Framework dependent deployment (FDD) Vs SCD (Self-Contained Deployment). In the case of FDD, you depend on the cloud or server infrastructure provided .NET Core version ( always uses the latest patch of the highest version specified)
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).
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#.
C# Version using Visual Studio – Option is disabled
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 .
Get C# Version using Command Prompt
Using Visual studio Command prompt:
csc /langversion:?
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
#error version
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 below techniques discussed,
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,
Do you have any comments or ideas or any better suggestions to share?
Please sound off your comments below.
Happy Coding !!
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.