1

After building and testing my solution on Visual Studio 2017 (target framework .NET 4.5, vs + resharper) I run it in production environment with Visual Studio 2015 (same target framework).

In this case I receive syntax error while trying to build it.

For example:

public double Frequency
{
    get => _frequency;
    set 
    {
        if (value > 0)
            _frequency = value;
    }
}

In VS 2015 I get:

"{ or ; expected"

Why does this happen?

musefan
  • 47,875
  • 21
  • 135
  • 185
Massimo Variolo
  • 4,669
  • 6
  • 38
  • 64

1 Answers1

3

The specific feature you are using for your get definition (expression-bodied members) is specific to C# version 7.0, as detailed here.

So the reason why your code is not compiling is because VS 2015 uses C# 6.0 and VS 2017 uses C# 7.0.

You can change you get declaration to the following in order to make it compatible with C# 6.0 and the it will build in VS 2015:

get { return _frequency; }

Although I have never tried it, after a quick look around the web, it seems it would be possible for you to use C# 7.0 with Visual Studio 2015 if you would prefer that option. Then you should in theory be able to compile your code without making any changes.

musefan
  • 47,875
  • 21
  • 135
  • 185
  • 1
    Ok but why is this happening? – Massimo Variolo Oct 04 '17 at 08:06
  • 1
    @MassimoVariolo: I have edited, and I will add some more information soon... I just want to double check a couple of things first – musefan Oct 04 '17 at 08:07
  • Even though it's the same framework C# 7 runs on the Roslyn compiler which is independent of the framework (kind of) –  Oct 04 '17 at 08:14
  • **How to use c# 7 in vs 2015** [link1](https://stackoverflow.com/questions/39461407/how-to-use-c7-with-visual-studio-2015) **How to change c# version in vs** [link2](https://www.codeproject.com/Tips/865579/How-to-change-targeted-Csharp-version-in-Visual-St) – Massimo Variolo Oct 04 '17 at 08:27