-1

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.

  1. So, my first question is: what are the different version numbers of the C# compilers for C# 4, 5 and 6?

  2. 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 Build Import directive for the Microsoft.Csharp.targets file from the MS Build bin folder. But I gave up reading from inside that file because I still don't fully understand all of the MS Build tags.

Water Cooler v2
  • 32,724
  • 54
  • 166
  • 336
  • Not real sure what the question is here. C# 5 obviously uses version 4.6 of the compiler. Where does the confusion come in? The other number ("1098") is just a minor revision/build number; presumably, there were multiple revisions made to the C# compiler. The first system you tried has a slightly newer version, probably a bug fix or two. They're both C# 5. Also, the compilers are backwards-compatible, meaning that the C# 5 compiler can target an older version of C#. You configure this with project options and/or compiler switches. – Cody Gray - on strike Apr 24 '17 at 11:46
  • Possible duplicate of [Difference between C# compiler version and language version](http://stackoverflow.com/questions/22814922/difference-between-c-sharp-compiler-version-and-language-version) – EpicKip Apr 24 '17 at 11:47
  • @CodyGray You could be right. The reason I ask is: on the VS 2013 machine, C# 5 features such as `CallerMemberAttribute` don't work. I wanted to know which version of the C# compiler VS 2013 was using to compile my code. – Water Cooler v2 Apr 24 '17 at 11:49
  • However, it does recognize the keywords `async` and `await`, which I believe were introduced in C# 5. – Water Cooler v2 Apr 24 '17 at 11:52

1 Answers1

1

what are the different version numbers of the C# compilers for C# 4, 5 and 6?

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

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?

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

enter image description here

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • Hasn't the C# compiler *always* been available as a standalone package? Originally, it shipped with the .NET Framework. I'm not sure if that's still true, since I've been mostly avoiding .NET for the past couple of releases. – Cody Gray - on strike Apr 25 '17 at 09:00
  • Yes, the C# compiler was available as a standalone package and shipped with the .net Framwork before Visual Studio 2013, starting from VS2013, C# compiler shipped with Visual Studio. – Leo Liu Apr 25 '17 at 10:09