Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

<LangVersion>latest</LangVersion> is not recognized by Visual Studio

Discussion in '2018.3 Beta' started by LazloBonin, Nov 6, 2018.

  1. LazloBonin

    LazloBonin

    Joined:
    Mar 6, 2015
    Posts:
    809
    Using 2018.3.0b7 for C# 7.2, and it compiles fine in the editor, but Visual Studio complains about every C# 7 language feature. Unity puts latest as the langversion in its generated csproj files, which doesn't seem to be recognized.
     
    dpoly likes this.
  2. LazloBonin

    LazloBonin

    Joined:
    Mar 6, 2015
    Posts:
    809
    Nevermind! It seems like it was only ReSharper complaining. Updating ReSharper to the latest version fixed all the errors when using C# 7 language features.
     
  3. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    We have the same issue but with Rider. We were on the latest version yesterday... I'll have to check again today! Maybe they released an update.
     
  4. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,132
    Was the issue resolved with a recent update?
     
  5. HarpSeal1

    HarpSeal1

    Joined:
    Oct 23, 2013
    Posts:
    35
    I'm having this trouble in visual studio 2018.3.0b9 . I'm not using any c# 7.2 features, but the langversion issue prevents the visual studio debugger from attaching to the unity process. Not as huge deal as the work around is to edit the Assembly-CSharp.csproj file and changing the langversion from latest to 6, but anyone doing this will have to redo this each time the project is compiled.
     
  6. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    Not resolved yet.. we just ignore the errors for now until it is fixed as we have a lot of work to get on with.

    The 2 types of errors we see are:
    • C# 7.1 Language feature
    • Cannot use Unsafe construct in safe context
      • And other related issues (Pointers may only be used in an unsafe context, etc).
    Our project compiles fine within Unity. I can confirm that the project files generated by Unity do not have the appropriate values set. For example, I enabled Unsafe code in the editor, but resharper requires me to open that assemblies/projects settings and tick the 'allow unsafe' checkbox. This value gets reset every time Unity regenerates the project files which seems to happen often. Same deal with the 7.1 issue.
     
  7. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,294
    The Rider plugin has an option to force the C# version:

    upload_2018-11-15_11-14-9.png

    That fixes the issue for me.
     
  8. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    This fixed our language version issues. But we still have a lot of issues related to using Unsafe code. And I figured out why... really strange..!

    Unity used to have an 'unsafe code' checkbox in player settings. We had that ticked on because one of our assemblies has unsafe code in it. Now the checkbox is on the asmdef itself? Our assembly that has unsafe code in it still compiles anyway. Which is strange..! It should be throwing errors, like Rider. Right?

    Ticking 'Allow unsafe' on the asmdef removed the rest of our errors. Unity still compiles as it did before, and Rider no longer complains..

    Strange!