Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

How do you change the target C# version for Visual Studio?

Discussion in '2018.3 Beta' started by OFFICIAL_bryanw, Dec 11, 2018.

  1. OFFICIAL_bryanw

    OFFICIAL_bryanw

    Joined:
    Jul 6, 2018
    Posts:
    36
    Hey All,

    I recently imported a package that uses C# 7.2 features, but my Unity projects all default to C# 7.0. I'm using the 4.x runtime equivalent and I'm on Unity 2018.3.0b12

    Cheers,
    Bryan
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,572
    By "Unity projects", do you mean the .csproj files generated by Unity, or the compilation of the C# code done in the Unity editor?
     
  3. OFFICIAL_bryanw

    OFFICIAL_bryanw

    Joined:
    Jul 6, 2018
    Posts:
    36
    The csproj's themselves. Right now it defaults to C#7 so when I try to debug my code the compilation fails when C#7.2 features are in the source

    I can manually change them myself but it ends up being pretty tedious
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,572
    At the moment, I think the geneated .csproj files specify the C# language version should be "latest". Is that what you see as well?

    That means Visual Studio will use the latest C# version Roslyn supports on your machine. Often you can work around this by updating to the latest version of Visual Studio.

    Longer term, we're working on changes now to emit the .csproj so that it uses the Roslyn version Unity ships with, which means it will use the exact same compiler and C# version Unity does, which is the correct solution.