0

I'm using unity 2020.1.1f1 , I recently noticed I'm using all of .NET 4.x features, new syntax like Auto-property initializers as in public int Health { get; set; } = 100; and so many others mentioned here

I get this for clrver command on Developer Command Prompt

Microsoft (R) .NET CLR Version Tool Version 4.7.2558.0 Copyright (c) Microsoft Corporation. All rights reserved.

Versions installed on the machine: v2.0.50727 v4.0.30319

Unity Player Settings, API Compatibility Level is .NET Standard 2.0

I've changed Assembly-CSharp.csproj v4.7.1 to v2.0 but it discards my changes and goes back to 4.7.1

I'm targeting mobile devices, I think .NET 2.0 is better for me but I don't know if whether Unity is actually using .NET 2 or .NET 4, since Unity Settings is set to use .NET Standard 2

enter image description here

1 Answer 1

1

The first is to update the NET version of VS: Project -> Properties.

Modify the .NET version used by the Unity project.

  1. In the Unity editor, click the menu Edit -> Project Setting -> Player.

  2. Select the corresponding .NET version in Scripting Runtime Version*.

enter image description here

reference link: https://docs.unity3d.com/Manual/dotnetProfileSupport.html.

Close VS. Check whether the Unity-related components are installed on the VS installer, and check it.

enter image description here

At this time, please check whether the Visual Studio Editor exists in the Unity of the current project: Window → Package Manager.

enter image description here

enter image description here

If it does not exist, switch Packages:Unity Registry in Package Manager, search for Visual Studio Editor, and click Install in the lower right corner.

enter image description here

Finally, Edit → Preferences... → External Tools, the selection box on the right side of the External Script Editor. Check the currently installed version of VS.

enter image description here

Reference document: https://learn.microsoft.com/en-us/visualstudio/gamedev/unity/troubleshooting/troubleshooting-and-known-issues-visual-studio-tools-for-unity#incompatible-project-in-visual-studio.

Hope it helps you.

Sign up to request clarification or add additional context in comments.

5 Comments

what version of unity are you using? I don't have that option which seems to be actually the solution to my problem, I'm using 2020
@Alireza Jamali I re-edited the answer. You can have a try. thanks.
thanks man but I have Visual Studio Editor in package manager and also External Tools is showing Microsoft Visual Studio 2019, I've searched the option in your picture, it was removed at newer versions of unity, the "Api Compability Level" is the only option related to .NET version of the project, my visual studio is using .NET 4 unlike the stated use of .NET 2 at Unity Settings, I don't think there's anything I can do about that
@Alireza Jamali In Unity 2019, it is no longer possible to switch to the old .NET 3.5 runtime. The only runtime is .NET 4.x.Unity official documentation: docs.unity.cn/cn/current/Manual/CSharpCompiler.html
it did not solve the problem but was helpful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.