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://learn.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.