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.
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.
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.
Was the issue resolved with a recent update?
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.
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.
The Rider plugin has an option to force the C# version:
That fixes the issue for me.
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!