I know that I've got the C# 6 compiler and I use C# 6 features often and when I write applications to practice, I usually target .NET v4.6.
On this machine, I have Visual Studio 2010, 2013, 2015 and 2017 installed.
When I type csc.exe
from the .NET Framework v4 directory, it shows me the compiler version as 4.6.1098.0 for C# 5, which is very confusing.
C:\Windows\Microsoft.NET\Framework64\v4.0.30319>csc Microsoft (R) Visual C# Compiler version 4.6.1098.0 for C# 5 Copyright (C) Microsoft Corporation. All rights reserved.
This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240
And when I type the same command on another laptop of mine where I have only Visual Studio 2013 installed, I get the following output from the csc.exe
command.
C:\Windows\Microsoft.NET\Framework64\v4.0.30319>csc Microsoft (R) Visual C# Compiler version 4.6.1055.0 for C# 5 Copyright (C) Microsoft Corporation. All rights reserved.
This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240
Observe that it reads 4.6.1055.0 for C# 5.
So, my first question is: what are the different version numbers of the C# compilers for C# 4, 5 and 6?
Second, how do I know which version of the
csc.exe
file, and thus which version of the C# compiler, my Visual Studio installation is using to compile my files? To try this on my own, I created a console application on each of my two machines and chased down the project files. They both had an MS BuildImport
directive for theMicrosoft.Csharp.targets
file from the MS Buildbin
folder. But I gave up reading from inside that file because I still don't fully understand all of the MS Build tags.
As the latest C# versions here, Visual Studio 2010 and Visual Studio 2013 are use the C# 4 & 5 compiler, and just as Cody Gray said, the compilers are backwards-compatible, meaning that the C# 5 compiler can target an older version of C#. So they are both C# 5. Besides, starting with Visual Studio 2013, MSBuild and the C# compilers are now available as a standalone package,Microsoft® Build Tools. This package is installed with Visual Studio 2013. Then you can get the version number of the C# 6 from the path: C:\Program Files (x86)\Microsoft Visual Studio 14.0
The csc.exe file in MSBuild folder is internal used by MSBuild. You can get the C# compiler version from the path:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\csc.exe