Is there any command to get the C# compiler version?
The csc
command seams has no option to show compiler version.
P.S
when I enter csc
command in Developer Command Prompt For VS2015 it returns:
Microsoft (R) Visual C# Compiler version 1.3.1.60616
Copyright (C) Microsoft Corporation. All rights reserved.
However I pretty sure my C# compiler is newer than 1.3!
C-value - also called the y-intercept of the parabola, this is where the x-value is zero, and graphically, this is where the graph intersects the y-axis.
Do keep in mind that you'll have a least 2 versions of csc.exe on your machine. One is shipped as part of the .NET Framework install, like it always was, and follows the version numbering of the framework. Stored in c:\windows\microsoft.net\framework\v4.0.30319, it is retained there for compatibility with System.CodeDom and sgen.exe. Frozen at C# language version 5. Most programmers right now will have version 4.7.x.0 when they have .NET v4.7 on their machine.
The other one got spun-off as part of the Roslyn project and is stored in the MSBuild directory. With a version number reset that start numbering again from 1. You'll run that one when you use the Developer Command Prompt. The most likely reason for the version number reset is their desire to not get locked into the framework release cadence, Roslyn suffered from a very large number of bugs that required intermediate releases to get fixed. A notable problem caused by the decoupling was the addition of the new ValueTuple type in C# v7, required by the much improved tuple support. The compiler shipped before the framework was available and programmers had to fall back to using a Nuget package for a while.
Version number resets don't happen very often. But another good example that everybody knows about is .NETCore, it got reset from 5.0 back to 1.0. I never saw a solid justification for that beyond "avoids confusion", I think it was a move to make it look fresh.
As a literal answer to the question new-ish [update: roslyn versions above 2, see comment by Cameron MacFarland] versions of csc do have a /version switch:
c:\>csc /version
2.3.2.62116 (8522b473)
For scripting purposes (if you want to switch on version say) that may be enough, along with testing the %errorlevel%
of csc /version
to place in a too old bucket.
/version
however does NOT appear at https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/listed-alphabetically (which seems the newest version) and I can't find anything listing at what version it was added.
UPDATE: I would also be very careful of the version number reported by csc, for example my personal 'default' is in C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Roslyn
and has version 2.3.2.62116
(and file date 22/9/2017) but I also have C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe
with version 4.7.2046.0
(and file date 18/03/2017) (and which doesn't take the /version switch).
So in answer to
Is there any command to get the C# compiler version?
I would say, yes, perhaps, sometimes but I would treat that version with a pinch of salt, Looking at the version stamps I have the version reported is the FIle Version of the csc.exe assembly which appears to come of the version the the 'larger entity' that compiled csc and there are at least incompatible numbering schemes for the Rosyln and 'Traditional' compilers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With