VSCode can't load C# project!

I open scripts by vscode, but get error, and There are no code hints!
Error info:

2023-07-27 20:12:35.538 [warning] The project file '/home/Workspace/U3DTrain/Assembly-CSharp.csproj' is in unsupported format (for example, a traditional .Net Framework project). It need be converted to new SDK style to work in C# Dev Kit.
2023-07-27 20:12:35.698 [error] Failed to load project '/home/Workspace/U3DTrain/Assembly-CSharp.csproj'. One or more errors occurred. (This project is not supported in C# Dev Kit.)
2023-07-27 20:12:35.709 [info] Project system initialization finished. 0 project(s) are loaded, and 1 failed to load.

Environment:

OS: Deepin 23(Debian 10.10)
Editor: VS-code(with plugins .NET Install Tool for Extension Authors, C#, C# Dev Kit, IntelliCode for c#, Debugger for Unity)
apt Installed: dotnet-sdk-7.0, mono-devel, mono-complete, mono-dbg

Version:

dotnet: 7.0
mono: 6.12.0.200
vscode: 1.80.1
UnityEditor: 2022.3.5f1 LTS

If you are getting this issue after you got the new update to the vs code and before everything was working normally
To solve the issue

  1. Download and install the official version of the unity extension . Announcing the Unity extension for Visual Studio Code - Visual Studio Blog
  2. Go to package manager and unity registry , search “studio” and update both extensions to recommended version.
  3. Open the VSCode and check for code completion
  4. If still no code completion , Open the project folder and there you can see all your csproj files for eg : “Assembly-CSharp.csproj”
  5. Open the csproj file and search for word “TargetFramework”. You will see one like this <TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
  6. <TargetFramework>net7.0</TargetFramework> copy this and paste under the step 5 line. Do same for all your csproj files if you have more than one.
    Now you can see code completion and syntax highliting etc.

I found another, less hacky, solution.

First, make sure you are using Unity 2021 or above

In VSCode:

In Unity

  • go to Window → Package Manager
  • remove the “Visual Studio Code Editor” package (it’s deprecated). If you’re unable to uninstall this might be because it’s part of the “Engineering feature set”. You can remove this package and add it’s contents manualy (you can see what’s part of this set here).
  • Install and/or update “Visual Studio Editor” (version 2.0.20+). From this version and higher it also includes Visual Studio Code support.

In File Explorer

  • Delete all .csproj and .sln files from your unity project folder (Make a back-up if you want)

In Unity

  • Go to Edit → Preferences → External Tools
  • Set VS Code as Code Editor
  • Click “Regenerate Project Files”
  • double click any script to open VSCode

Thank you shamsad for pointing me in the right direction. Also thanks to this issue page on Github (github .com/microsoft/vscode-dotnettools/issues/271#issuecomment-1672096480)

Sorry for the misformatted links. As a new user I’m not allowed to post more links.

Solution:
In a word:
Install “Unity” extension in Visual Studio Code and Update the “Visual Studio Editor” package to at least 2.0.20 in Unity Package Manager.

Details:

  1. In Visual Studio Code, search “Unity” in Extension marketplace and install it. In the details of “Unity” extension, you also can find the requirements Unity settings.

  2. In Unity, WindowPackage Manager, find “Visual Studio Editor”, Unlock it and Update it to the latest version (2.0.20+).


  3. In Unity, SettingsExternal Tools, select “Visual Studio Code”, make sure it shows “Visual Studio Editor v2.0.20 enabled” (the version same as you installed in the previous step), then Regenerage project files.

  4. Then back to Visual Studio Code, just click F5 to start your happy debugging.

In VSCode go to settings and look for omnisharp.useModernNet
uncheck and restart VS Code
Load unity solution from unity
Autocomplete should work.
make sure you have dotnet SDK and MS build tools installed.

Hope this helps,
Rahul

It seems like both files Assembly-CSharp-Editor.csproj and Assembly-CSharp.csproj are missing the line:
<TargetFramework>net7.0</TargetFramework>
After adding it everything works fine.

The question is, how to make this permanent? Because every new project will be generated, it misses the TargetFramework on both files, any fix for Unity on that?

Thank you so much. I’ve spent all night looking for a solution and nothing worked. Nothing, except this. Thank you again