-2

I have a funny situation where the C# project targets version of .NET framework depending on Visual Studio version rather than depending on selected .NET target version in Application tab of project's properties.
I had VS2013 premium, update 4, installed and the given project targets .NET 3.5.
Afterwards I've installed VS2015 Enterprise edition and opened solution with the given project with VS2015. Resharper suggested use of nameof() operator (which is .NET 6.0 feature) and this compiled, but when I open given solution in VS2013 it doesn't compile anymore.

Here's the screenshot of Application tab for the given project:
enter image description here

Here's the code snippet from the project when I open it in VS2015: enter image description here
Which compiles successfully.

And here's the code snippet from the project when I open it in VS20103:
enter image description here
Which doesn't compile.

Any clues about this?

UPDATE:
To rephrase my question. Why does the given project (that targets .NET 3.5) compile at all in VS2015 even though I've used .NET 6.0 feature (nameof() operator)?

dragan.stepanovic
  • 2,955
  • 8
  • 37
  • 66
  • 1
    You can't use the latest if you dont have VS2015 since it doesn't have the Roslyn compliler. Same for the rest – Mihai Bratulescu Aug 31 '15 at 11:18
  • 1
    *which is .NET 6.0 feature* No, it's not. – ta.speot.is Aug 31 '15 at 11:26
  • http://www.c-sharpcorner.com/UploadFile/7ca517/the-new-feature-of-C-Sharp-6-0-nameof-operator – dragan.stepanovic Aug 31 '15 at 11:27
  • 1
    That's C# 6 not .NET 6 – ta.speot.is Aug 31 '15 at 11:27
  • Actually, nameof is C# 6 features, not .NET (which is still in 4.6 btw), check the Advanced Build Settings (Project Properties-Build-Advanced) if your language version is set to C# 5.0 – Martheen Aug 31 '15 at 11:29
  • 1
    Context for mixing different versions of Visual Studio safely: http://ericlippert.com/2013/04/04/what-does-the-langversion-switch-do/ – ta.speot.is Aug 31 '15 at 11:31
  • So actually you're saying that because Language version is set to default in VS2015 (I would guess that maps to C# 6.0) this code compiles and I should switch it to C# 3.0? http://stackoverflow.com/questions/247621/what-are-the-correct-version-numbers-for-c/247623#247623 – dragan.stepanovic Aug 31 '15 at 11:38
  • 1
    @kobac - Yes if you witch your Language Version to C# 3.0 the compiler will only allow you to language features from that version of C#. Your source code would still compile in Visual Studio 2008. If you are only worried about still supporting VS2013, you can set your Language Version to C# 5.0, since VS2013 will support that. – shf301 Aug 31 '15 at 13:44
  • @shf301 great, thanks! – dragan.stepanovic Aug 31 '15 at 13:50

1 Answers1

0

This is normal behaviour. If you try to compile something .NET 4.0 specific in VS 2005, you will get the same result. Using a certain VS version you can only develop using up to a certain .NET version.

If I remember correctly:

VS 2005 - .NET 2.0
VS 2008 - .NET 3.5
VS 2010 - .NET 4.0
VS 2013 - .NET 4.5

Update: The .NET version is indeed not relevant in this case, as the nameof operator is a feature of the Roslyn compiler. Nothing more, nothing less. The VS 2013 definitely uses a different one (at least a compiler which does not cover up with C# 6), therefore it does not compile.

Pedro Isaaco
  • 404
  • 3
  • 10
  • 1
    There's a nice answer by Jon Skeet here that explains the version numbers: http://stackoverflow.com/questions/247621/what-are-the-correct-version-numbers-for-c/247623#247623 – Heki Aug 31 '15 at 11:24
  • 1
    *If you try to compile something .NET 4.0 specific in VS 2005* That's not really relevant because this is about a language feature that's not tied to the .NET Framework version. – ta.speot.is Aug 31 '15 at 11:29