vendredi 8 août 2014

.net - différence entre la version du compilateur c# et la version de langue - Stack Overflow


There was time I thought that the Framework version and the C# version are the same things, so once you install the next Framework version on the computer, you should use it.


Then I found out that the framework is not linked directly with the C# version, and on the same machine multiple C# compilers can be cohabitate, so probably the compiler and C# version should be the same.


Now I understand that the compiler version and the C# version are not the same...




Visual Studio Command Prompt (2010): C:\>csc


Microsoft (R) Visual C# Compiler version 4.0.30319.33440
for Microsoft (R) .NET Framework 4.5




Developer Command Prompt for VS 2013: C:\>csc


Microsoft (R) Visual C# Compiler version 12.0.30110.0
for C# 5




enter image description here


we can see that
- VS 2010 uses a compiler version 4.0 for the C#4 (?? I just can suppose it, because not explicitly mentioned);
- VS 2013 uses the compiler version 12.0 fo the C# 5 (this is explicitly mentioned)


Knowing that compiling using different language versions could bring different results to the user


Questions



  • How to find out what C# version (not the compiler one, but the language one) uses VS to build my concrete project?


  • Is there a strict, clear and transparent link between the C# compiler and language versions?


  • Can I indicate to Visual Studio (in case of migration issues from one Studio version to another) to use different compiler version for my concrete solution?





In the past Visual Studio 2005 was fixed only to one .Net version and C# compiler delivered with this version. In case you want use newer version of VS you have to switch Visual Studio as well. Now Visual studio can target to more than one .Net version and it can even mix new C# compiler with old .Net framework (lambdas or extension methods in .Net 2.0). Simply C# compiler version is related to C# language version.


You can check your compiler version in project file (open it as xml) and there is ToolsVersion attribute of Project element.


In my specific project there is ToolsVersion="4.0" and my target project is .Net 2.0. It means I can use new language construct in old framework which is not possible in VS2005.



There was time I thought that the Framework version and the C# version are the same things, so once you install the next Framework version on the computer, you should use it.


Then I found out that the framework is not linked directly with the C# version, and on the same machine multiple C# compilers can be cohabitate, so probably the compiler and C# version should be the same.


Now I understand that the compiler version and the C# version are not the same...




Visual Studio Command Prompt (2010): C:\>csc


Microsoft (R) Visual C# Compiler version 4.0.30319.33440
for Microsoft (R) .NET Framework 4.5




Developer Command Prompt for VS 2013: C:\>csc


Microsoft (R) Visual C# Compiler version 12.0.30110.0
for C# 5




enter image description here


we can see that
- VS 2010 uses a compiler version 4.0 for the C#4 (?? I just can suppose it, because not explicitly mentioned);
- VS 2013 uses the compiler version 12.0 fo the C# 5 (this is explicitly mentioned)


Knowing that compiling using different language versions could bring different results to the user


Questions



  • How to find out what C# version (not the compiler one, but the language one) uses VS to build my concrete project?


  • Is there a strict, clear and transparent link between the C# compiler and language versions?


  • Can I indicate to Visual Studio (in case of migration issues from one Studio version to another) to use different compiler version for my concrete solution?




In the past Visual Studio 2005 was fixed only to one .Net version and C# compiler delivered with this version. In case you want use newer version of VS you have to switch Visual Studio as well. Now Visual studio can target to more than one .Net version and it can even mix new C# compiler with old .Net framework (lambdas or extension methods in .Net 2.0). Simply C# compiler version is related to C# language version.


You can check your compiler version in project file (open it as xml) and there is ToolsVersion attribute of Project element.


In my specific project there is ToolsVersion="4.0" and my target project is .Net 2.0. It means I can use new language construct in old framework which is not possible in VS2005.


0 commentaires:

Enregistrer un commentaire