Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Unity VS package generates csproj with wrong language version

Discussion in 'Editor & General Support' started by Xtro, Sep 15, 2021.

  1. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    604
    Bug report: https://fogbugz.unity3d.com/default.asp?1365496_3glhf07k25hpr8vn
    Issue tracker: https://issuetracker.unity3d.com/is...erates-csproj-with-the-wrong-language-version

    Unity VS package generates csproj files with <LangVersion>latest</LangVersion> which is the wrong C# version for Unity.
    Because of this bug, Visual Studio and VS Resharper plugin are suggesting C# 9 code improvements which are not supported by Unity yet.

    My tool versions:
    Unity 2021.1.15
    Unity VS package 2.0.11
    Visual Studio 2019 [16.11.31624] (This is selected as External Script Editor in Unity preferences)

    Repro steps:
    1. Open the attached project in Unity and see that there is only one script called Script1.
    2. Go to External Tools section in Unity preferences window and click "Regenerate project files" button.
    3. Open project root folder in computer's file browser app.
    4. Right click on "Assembly-CSharp.csproj" file and open it in a text editor (Avoid using VS for this to be able to isolate the bug).
    5. See <LangVersion>8.0</LangVersion> entry in the text editor which is the correct C# version for Unity.
    6. Close the text editor.
    7. Right click on Assets folder in Unity project window, create a new script and name it as "Script2".
    8. Wait for Unity to recompile (Even for an empty project, it takes very long bug that's another problem).
    9. Open "Assembly-CSharp.csproj" file in text editor again.
    10. See <LangVersion>latest</LangVersion> entry which is the wrong C# version for Unity.
    This problem happens randomly but very frequently. If you don't see the wrong C# version in step 10, repeat the process starting from step 7 and use a different script name everytime like Script3, Script4... The bug is going to occur eventually. For me it happens for Script2 or Script3 very frequently.
    11. Go to External Tools section in Unity preferences window and click "Regenerate project files" button again.
    12. Open "Assembly-CSharp.csproj" file in text editor again.
    13. See that this button fixes the C# version: <LangVersion>8.0</LangVersion>
    14. You can continue this loop starting from step 7 again.
     
    Last edited: Oct 18, 2021
    sonnyb likes this.
  2. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    604
    QA closed the ticket saying it's fixed in a future version. I haven't tested it yet.

    ---
    Unity Bug Reporting Portal
    Today 3:22 AM

    All fixes for this bug report have been resolved and closed.

    Summary:

    Branch:2.0.X
    Resolution: Fixed
    Fix Versions: 2.0.18
    Verified against: 2021.3.28f1
    Resolution Notes: