What Version Is My C# Compiler?
-
I ran across a Stack Overflow post that stated that C# 7.3 supports a new feature in which I am keenly interested. The obvious next question is whether I have C# 7.3, and how do I find out? The answer given elsewhere on SO works great on the dedicated C# compiler, but falls short on the new Roslyn compiler. The new command, along with an example of its output from my installation, follows.
C:\Users\DAG 2018/08/13 20:21:18.28>"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Roslyn\csc.exe" /langversion:?
Supported language versions:
default
1
2
3
4
5
6
7.0 (default)
7.1
7.2
7.3 (latest)
latestC:\Users\DAG 2018/08/13 20:21:31.33>
David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
-
I ran across a Stack Overflow post that stated that C# 7.3 supports a new feature in which I am keenly interested. The obvious next question is whether I have C# 7.3, and how do I find out? The answer given elsewhere on SO works great on the dedicated C# compiler, but falls short on the new Roslyn compiler. The new command, along with an example of its output from my installation, follows.
C:\Users\DAG 2018/08/13 20:21:18.28>"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Roslyn\csc.exe" /langversion:?
Supported language versions:
default
1
2
3
4
5
6
7.0 (default)
7.1
7.2
7.3 (latest)
latestC:\Users\DAG 2018/08/13 20:21:31.33>
David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
That output looks like the command works as expected. What were you expecting to see? :confused: Your compiler supports C# 7.3, but defaults to 7.0. To turn on 7.3, you need to change the advanced build settings. Open the properties of your project, select the "Build" tab, click the "Advanced" button, and select the language version you want. NB: For some bizarre reason, you need to change the version separately for each build configuration. 4 ways to enable the latest C# features - Meziantou's blog[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
That output looks like the command works as expected. What were you expecting to see? :confused: Your compiler supports C# 7.3, but defaults to 7.0. To turn on 7.3, you need to change the advanced build settings. Open the properties of your project, select the "Build" tab, click the "Advanced" button, and select the language version you want. NB: For some bizarre reason, you need to change the version separately for each build configuration. 4 ways to enable the latest C# features - Meziantou's blog[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
My point is that the instructions in the SO post, [which version of C# am I using - Stack Overflow](https://stackoverflow.com/questions/19532942/which-version-of-c-sharp-am-i-using), which I forgot to cite, imply that it's in the general help message displayed when you pass the compiler "/?" to display the general help message. While that command yields lots of useful tidbits, you must amplify it a bit to get the list of supported C# language versions. Nevertheless, your reply called to my attention something which I hadn't noticed, which is that the default version in my installation is 7.0, not 7.3, as at first appeared to be the case. Thanks for the additional tidbits about how to override that. Of the four ways mentioned, the one that calls to me is the properties file, since that supports overriding all sorts of default values for every project. Though I haven't dug into the global property sheets for C#, I've made extensive changes to my C++ settings.
David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
-
My point is that the instructions in the SO post, [which version of C# am I using - Stack Overflow](https://stackoverflow.com/questions/19532942/which-version-of-c-sharp-am-i-using), which I forgot to cite, imply that it's in the general help message displayed when you pass the compiler "/?" to display the general help message. While that command yields lots of useful tidbits, you must amplify it a bit to get the list of supported C# language versions. Nevertheless, your reply called to my attention something which I hadn't noticed, which is that the default version in my installation is 7.0, not 7.3, as at first appeared to be the case. Thanks for the additional tidbits about how to override that. Of the four ways mentioned, the one that calls to me is the properties file, since that supports overriding all sorts of default values for every project. Though I haven't dug into the global property sheets for C#, I've made extensive changes to my C++ settings.
David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
I never got that too, why not default to the latest stable release?
Nish Nishant Consultant Software Architect Ganymede Software Solutions LLC www.ganymedesoftwaresolutions.com
-
I never got that too, why not default to the latest stable release?
Nish Nishant Consultant Software Architect Ganymede Software Solutions LLC www.ganymedesoftwaresolutions.com
Nish Nishant wrote:
why not default to the latest stable release?
If it was that easy... everyone could do it :rolleyes: :rolleyes: :laugh: :laugh:
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
-
I never got that too, why not default to the latest stable release?
Nish Nishant Consultant Software Architect Ganymede Software Solutions LLC www.ganymedesoftwaresolutions.com
That's exactly what I expected it to do. However, I can understand some motivation for setting it to the last whole version.
David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
-
I never got that too, why not default to the latest stable release?
Nish Nishant Consultant Software Architect Ganymede Software Solutions LLC www.ganymedesoftwaresolutions.com
I think the idea is to avoid breaking previously-compiling code unless you ask it to. :) (I haven't seen any C# 7.0 code that would be broken by the 7.3 compiler; but it's always best to CYA.)
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
I think the idea is to avoid breaking previously-compiling code unless you ask it to. :) (I haven't seen any C# 7.0 code that would be broken by the 7.3 compiler; but it's always best to CYA.)
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Yeah, but Visual Studio 2017 defaults to 7.0 for new projects too.
Nish Nishant Consultant Software Architect Ganymede Software Solutions LLC www.ganymedesoftwaresolutions.com
-
Yeah, but Visual Studio 2017 defaults to 7.0 for new projects too.
Nish Nishant Consultant Software Architect Ganymede Software Solutions LLC www.ganymedesoftwaresolutions.com
I agree, it's annoying. You can apparently override it by putting a magic file in a directory somewhere above your project: Customize your build - Visual Studio | Microsoft Docs[^]
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
</PropertyGroup>
</Project>But I don't like that solution. As soon as you share your project with someone who doesn't have the magic file, they'll start getting compiler errors for all the new features.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
I agree, it's annoying. You can apparently override it by putting a magic file in a directory somewhere above your project: Customize your build - Visual Studio | Microsoft Docs[^]
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
</PropertyGroup>
</Project>But I don't like that solution. As soon as you share your project with someone who doesn't have the magic file, they'll start getting compiler errors for all the new features.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Thanks, good to know.
Nish Nishant Consultant Software Architect Ganymede Software Solutions LLC www.ganymedesoftwaresolutions.com