Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# Dev Kit Support for Unity Projects #271

Closed
MahmoudKanbar opened this issue Jul 18, 2023 · 42 comments
Closed

C# Dev Kit Support for Unity Projects #271

MahmoudKanbar opened this issue Jul 18, 2023 · 42 comments
Labels
area-unity Unity support enhancement New feature or request

Comments

@MahmoudKanbar
Copy link

MahmoudKanbar commented Jul 18, 2023

Describe the feature you'd like

Whenever I try to open a unity project in VSCode using the new C# Dev Kit I get the following warning messages for each project
[warning] The project file 'PATH TO THE .CSPROJ FILE' 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.

image

Opening Unity C# projects in the new extension will be very useful for a lot of programmers.
And thanks for the amazing extension.

Alternatives considered

No response

Environment Information

No response

@MahmoudKanbar MahmoudKanbar added the enhancement New feature or request label Jul 18, 2023
@timheuer timheuer added the area-unity Unity support label Jul 19, 2023
@vazab
Copy link

vazab commented Jul 20, 2023

I also start getting an error:
[error] Failed to load project 'path\Assembly-CSharp.csproj'. One or more errors occurred. (This project is not supported in C# Dev Kit.)
This is probably related to .NET Framework 4.8 because it's built into Windows 10. When as the target framework it's 4.7.1 for csproj

@WagnerWD40
Copy link

Same error here using linux Mint

@ashtonland
Copy link

Also having this problem using windows 11. Tried installing .NET 4.7.1 SDK and targeting pack to no avail. Seems purely due to the bit older format of unity generated csproj files. I find that a project will succeed at loading when i add the Sdk="Microsoft.NET.Sdk" property to Unity's generated <Project toolsVersion="4.0" ... /> property. I assume this is the "new SDK" style that the error above to which the above error referred. Also I had to add
<TargetFramework>net6.0</TargetFramework> within the property group to eliminate one of the warnings.

However, while the projects will load, the solution viewer will be useless because, since Unity csproj files are generated in the root directory, each project in the solution viewer just shows the entire project file system like the regular view. This could be fixed oneself by moving your assembly's .csproj file in the folder alongside the assembly definition file, but unity will just regenerate that csproj file at the root directory the next yo you compile your code so that doesn't work either & this regeneration removes the property changes/additions that I stated above which causes the projects to fail to compile once more and back at the beginning...

So evidently I was unable to fix the problem, but I have uncovered why it occurs and what needs to be don't to fix it so hopefully it can help the DevKit team resolve this by making some special treatment for Unity C# Projects :)

@Facewade
Copy link

So, im super new to unity and got this problem too, the thing is, my intelissense is not working, and i thought this was related, is it?

@WagnerWD40
Copy link

WagnerWD40 commented Aug 1, 2023 via email

@AvilaMoralesD
Copy link

AvilaMoralesD commented Aug 1, 2023

I subscribe, mine doesn't work either
The project file 'c:\somethingsomething.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.

@perrylets
Copy link

Not working for me as well. Now it's impossible to use Unity with VS Code a few days after Unity posted a guide on how to debug with VS Code (debugging with unity is different). You can't use one of the most famous use cases of C# with VS Code, great idea.

@Chizaruu
Copy link

Chizaruu commented Aug 4, 2023

Describe the feature you'd like

Whenever I try to open a unity project in VSCode using the new C# Dev Kit I get the following warning messages for each project [warning] The project file 'PATH TO THE .CSPROJ FILE' 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.

image

Opening Unity C# projects in the new extension will be very useful for many programmers. And thanks for the amazing extension.

Alternatives considered

No response

Environment Information

No response

You have two options for SDK style csproj.

  1. Use the new "officially" supported package for VSCode, the standard Visual Studio Package (v2.0.20), on the Unity Package Manager.

or

  1. Use my package for VSCode support, which generates SDK Style csproj and is more community focused.

Note that you can't have both packages installed simultaneously for reasons that only Microsoft & Unity know. (See Chizaruu/com.tsk.ide.vscode#77 for more details)

@jbevain
Copy link
Member

jbevain commented Aug 4, 2023

We just announced the addition of the Unity extension for Visual Studio Code to the C# Dev Kit family of extensions, currently in preview. Make sure to follow the Getting Started guide and you should be good to go.

I'm going to close this issue, but feel free to create new issues if you encounter problems with the preview!

@jbevain jbevain closed this as completed Aug 4, 2023
@jbevain
Copy link
Member

jbevain commented Aug 4, 2023

@Chizaruu

Note that you can't have both packages installed simultaneously for reasons that only Microsoft & Unity know. (See Chizaruu/com.tsk.ide.vscode#77 for more details)

Feel free to open a new issue to track this. The behavior and code your highlight in your GitHub issue is simply a way to avoid a conflict between the Visual Studio Code support in the Visual Studio Editor Unity Package that we work on in collaboration with Unity, and the Visual Studio Code Editor Unity Package that Unity previously maintained and now stopped supporting (but is still installed in many Unity versions).

We'd be happy to look at only disabling the legacy and unmaintained Unity Package that Unity still ships if that conflicts with your package.

@Chizaruu
Copy link

Chizaruu commented Aug 4, 2023

@Chizaruu

Note that you can't have both packages installed simultaneously for reasons that only Microsoft & Unity know. (See Chizaruu/com.tsk.ide.vscode#77 for more details)

Feel free to open a new issue to track this. The behavior and code your highlight in your GitHub issue is simply a way to avoid a conflict between the Visual Studio Code support in the Visual Studio Editor Unity Package that we work on in collaboration with Unity, and the Visual Studio Code Editor Unity Package that Unity previously maintained and now stopped supporting (but is still installed in many Unity versions).

We'd be happy to look at only disabling the legacy and unmaintained Unity Package that Unity still ships if that conflicts with your package.

Sounds like a plan, thanks for letting me know!

@nguyenminhtri10061997
Copy link

try open Assembly-CSharp.csproj file, add new line value is net sdk you installed before ex:
<TargetFramework>net7.0</TargetFramework>
in below
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>

@ajkolenc
Copy link

ajkolenc commented Aug 4, 2023

Describe the feature you'd like

Whenever I try to open a unity project in VSCode using the new C# Dev Kit I get the following warning messages for each project [warning] The project file 'PATH TO THE .CSPROJ FILE' 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.
image
Opening Unity C# projects in the new extension will be very useful for many programmers. And thanks for the amazing extension.

Alternatives considered

No response

Environment Information

No response

You have two options for SDK style csproj.

  1. Use the new "officially" supported package for VSCode, the standard Visual Studio Package (v2.0.20), on the Unity Package Manager.

or

  1. Use my package for VSCode support, which generates SDK Style csproj and is more community focused.

Note that you can't have both packages installed simultaneously for reasons that only Microsoft & Unity know. (See Chizaruu/com.tsk.ide.vscode#77 for more details)

Upgrading to the latest Visual Studio Package (v2.0.20) fixed this issue for me, I didn't realize that package was involved. Thank you!

@enjoy-software
Copy link

Follow this document Unity Development with VS Code.
Finally when you reopen the project, unity editor will automatically update .csproj.

@prakyath-07
Copy link

Delete all CsProj files and soltuion files from the root, and regenerate the files from settings (Edit->Preferences->Regenerate Project Files)

@daniel-keen
Copy link

Can something please be ever released without any critical issues that block the workflow....
Anyway, I have the same issue as the TS.

@afiyindev
Copy link

Im having this same issue, ive updated to version 2.0.20 but it still doesnt work

@Reyder95
Copy link

Reyder95 commented Aug 8, 2023

Having the same issues as well. Downloading the 2.0.20 version of Visual Studio Editor, as well as Visual Studio Code Editor, and regenerating files etc still provides me with

The project file '...\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.

Tried pretty much everything here (deleting then regenerating files etc) and nothing seems to work.

@askor
Copy link

askor commented Aug 9, 2023

Removing the Visual Studio Code Editor package and updating Visual Studio Editor in Unity Package Manager fixed it for me.

@afiyindev @Reyder95 @daniel-keen

@Emberstorm-John
Copy link

Emberstorm-John commented Aug 9, 2023

Complete guide that worked for me: (from answes above)

  • Make sure you are using Unity 2021 or above
  • Install VSCode Unity Extension https://marketplace.visualstudio.com/items?itemName=VisualStudioToolsForUnity.vstuc
  • In Unity go to Window -> Package Manager
    -- Uninstall Visual Studio Code Editor package
    -- Install and or Update Visual Studio Editor (version 2.0.20+)
  • In windows delete all .csproj and .sln files from your unity project folder
  • In Unity go to Edit -> Preferences -> External Tools
    -- Set VS Code as Code Editor
    -- Click Regenerate Project Files
  • In Unity double click any script to open VSCode

@honzapatCZ
Copy link

<TargetFramework>net7.0</TargetFramework>

Well, what if you dare to use Unity 2020?
What should one do?

@alcidesbava
Copy link

I already did everything said here and nothing works! this is fuckin hell!

@alcidesbava
Copy link

Having the same issues as well. Downloading the 2.0.20 version of Visual Studio Editor, as well as Visual Studio Code Editor, and regenerating files etc still provides me with

The project file '...\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.

Tried pretty much everything here (deleting then regenerating files etc) and nothing seems to work.

.
.
.

have yousolved the problem?

@broseidon91
Copy link

broseidon91 commented Aug 13, 2023

Having the same issues as well. Downloading the 2.0.20 version of Visual Studio Editor, as well as Visual Studio Code Editor, and regenerating files etc still provides me with
The project file '...\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.
Tried pretty much everything here (deleting then regenerating files etc) and nothing seems to work.

. . .

have yousolved the problem?

Late Edit: It seems like the Visual Studio Editor package version 2.0.20 and above solve this issue automatically.

  1. Open your package manager, go to the Unity Registry and find Visual Studio Editor.
  2. If it is locked, click Unlock, then click on the Version History tab.
  3. Find the latest recommended version, make sure it is at least 2.0.20 (at time of writing, it was up to 2.0.22)
  4. Install that
  5. Delete all of the .csproj files in your project
  6. Open Unity settings, Navigate to External Tools. Click "Regenerate project files".
  7. VsCode should be working at this point.

If you don't want to delete your csproj files, use the method below


After failing to solve it on this page, i found this: https://discussions.unity.com/t/vscode-cant-load-c-project/273373

Particularly, nothing worked until I added <TargetFramework>netstandard2.1</TargetFramework> in my Assembly-CSharp.csproj file, just under <TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>. After saving, VSCode properly loaded the project.

Here are the steps

  1. Open

  2. Download and install the official version of the unity extension . Announcing the Unity extension for Visual Studio Code - Visual Studio Blog 137

  3. Go to package manager and unity registry , search “studio” and update both extensions to recommended version.

  4. Open the VSCode and check for code completion

  5. If still no code completion , Open the project folder and there you can see all your csproj files for eg : “Assembly-CSharp.csproj”

  6. Open the csproj file and search for word “TargetFramework”. You will see one like this <TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>

  7. <TargetFramework>netstandard2.1</TargetFramework> copy this and paste under the step 5 line. Do same for all your csproj files if you have more than one.

  8. Now you can see code completion and syntax highliting etc.

Since I hadn't coded on my home PC in awhile, I also updated to the latest C# SDK before I did these steps. https://dotnet.microsoft.com/en-us/download

@rdvansloten
Copy link

rdvansloten commented Aug 13, 2023

try open Assembly-CSharp.csproj file, add new line value is net sdk you installed before ex:
<TargetFramework>net7.0</TargetFramework>
in below
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>

Oh my god, this actually works, on MacOS at least:

<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<TargetFramework>net7.0</TargetFramework>

And the output (after 22:26 is when I changed it and saved)


2023-08-13 22:26:33.260 [info] Project system initialization finished. 1 project(s) are loaded, and 0 failed to load.

Life saver! Thank you @nguyenminhtri10061997 !

@abelbascu
Copy link

abelbascu commented Aug 17, 2023

  1. If still no code completion , Open the project folder and there you can see all your csproj files for eg : “Assembly-CSharp.csproj”
  2. Open the csproj file and search for word “TargetFramework”. You will see one like this <TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
  3. <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.

Since I hadn't coded on my home PC in awhile, I also updated to the latest C# SDK before I did these steps. https://dotnet.microsoft.com/en-us/download

Worked for me too, thanks!!

@rami-husein
Copy link

FWIW, I think you should add the line <TargetFramework>NET_STANDARD_2_1</TargetFramework> instead, since that is the API level that unity supports.

@timdv91
Copy link

timdv91 commented Aug 23, 2023

I finally got it to work on Linux, with Unity 2022.3.7f1. Only wasted 4.5 hours of my life...

1. Getting .NET to work:

Install the dotnet packages using pamac: Screenshot from 2023-08-23 14-08-06

2. Getting intelissense to work:

Install the Microsoft C# package for VS Code v1.26.0
Screenshot from 2023-08-23 15-26-16

3. Configure VS Code editor in Unity:

3.1 Go to Window --> Package Manager --> Packages: In Project --> Visual Studio Code Editor must be enabled and installed.
Screenshot from 2023-08-23 14-40-24

3.2 Click the 'unlock' button, if required...
Screenshot from 2023-08-23 14-44-31

@lalan-desai
Copy link

try open Assembly-CSharp.csproj file, add new line value is net sdk you installed before ex: <TargetFramework>net7.0</TargetFramework> in below <TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>

Thank you very much it worked for me :)

@vivekchdry
Copy link

vivekchdry commented Sep 4, 2023

<TargetFramework>net7.0</TargetFramework>

Well, what if you dare to use Unity 2020? What should one do?

Updating to Visual Studio Editor (version 2.0.20)
Worked for me, with using Unity 2020.3.40f1

@Novack
Copy link

Novack commented Sep 4, 2023

Using Unity 2019.4 here. One silly thing that was making things difficult for me, was not closing and relaunching Unity after making package changes. I asumed this was not required, but finally proved to help.

@Killerbiene10
Copy link

Killerbiene10 commented Sep 6, 2023

I've had the same issue, followed all the tips and it went from that error above to this:

No installed .NET SDK was found on the computer. If it is installed, make sure it can be found through the PATH environment variable. C# Dev Kit does not work without a supported version of SDK. After installing the SDK, you need restart the VS Code session, or the computer.

Screenshot 2023-09-05 at 10 04 17 PM

I have tried uninstalling, re-installing, setting a path manually, regenerate project files, adding the framework lines up there.

Screenshot 2023-09-05 at 10 06 11 PM

I've added the lines:

v4.7.1
net7.0

Whenver i reopen Unity the csprod files go back to "2.0"I am absolutely at the end of my rope here, completely overwhelmed as to what to do next. I can't work on anything until I have figured this out ...

@Feacur
Copy link

Feacur commented Sep 6, 2023

TWIMC, if you want to automate patching *.csproj, look somewhat in this direction

using UnityEditor;

public class SolutionPostprocessor : AssetPostprocessor
{
    // https://learn.microsoft.com/en-us/visualstudio/gamedev/unity/extensibility/customize-project-files-created-by-vstu
    // https://github.com/MicrosoftDocs/visualstudio-docs/blob/main/gamedev/unity/extensibility/customize-project-files-created-by-vstu.md

    // public static string OnGeneratedSlnSolution(string path, string content)
    // {
    //     return content;
    // }

    public static string OnGeneratedCSProject (string path, string content)
    {
        PatchCSProjectForVSCode();
        return content;

        void PatchCSProjectForVSCode()
        {
            const string tag = "<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>";
            int index = content.IndexOf(tag);
            if (index < 0) { return; }
            // @note: as of now, hierarchy is <Project> -> <PropertyGroup> -> this tag;
            //        Unity indents blocks with `  `, double space
            content = content.Insert(index + tag.Length, $"{System.Environment.NewLine}    <TargetFramework>net7.0</TargetFramework>");
        }
    }
}

P.S.: I'm using 2020.3.40f1, because that's my fixed version for releases currently.

@ck9706
Copy link

ck9706 commented Sep 8, 2023

Maybe can solve this problem:Delete all CsProj files and solution files from the root directory, then regenerate files from Settings (Edit -> Preferences -> Regenerate project files)

@Killerbiene10
Copy link

Thank you guys - I've solved my issue simply by moving to my PC and using Visual Studio instead. For some reason that works completely fine, and even on my Mac it works much better. VSCode still gets the same errors, but that's a problem for the future, I've wasted enough time on this.

@LeonSolisPedro
Copy link

I'm also moving to Visual Studio instead, the C# Dev Kit its so buggy for me, and the documentation is so confusing,I wasted so much time trying to make things work.

@himanshu-nag
Copy link

To resolve the issue of the Unity assembly C# file being in an unsupported format, you'll need to convert it to the new SDK style. Here are the steps to do so:

  1. Open your Unity project in Unity Editor.
  2. In the Project window, locate the C# file that is causing the error.
  3. Right-click on the file and select "Open C# Project" or "Open in External IDE" (depending on your Unity version).
  4. This will open the C# project in your preferred Integrated Development Environment (IDE), such as Visual Studio or Visual Studio Code.
  5. In the IDE, right-click on the project file (usually ending with .csproj) and select "Unload Project" or a similar option.
  6. Once the project is unloaded, right-click on the project file again and select "Edit Project File" or "Edit .csproj" (again, the option may vary depending on the IDE).
  7. This will open the project file in a text editor.
  8. Look for the tag and add the following line inside it:
    latest
  9. Save the changes and close the text editor.
  10. Go back to Unity Editor and right-click on the C# file.
  11. Select "Reload All" or "Reload Scripts" to reload the updated project file.
  12. Unity will now recompile the C# scripts, and the error should be resolved.

@rootdog404
Copy link

rootdog404 commented Sep 13, 2023

DONT forget to restart Unity after plug-ins updated.

@gizzye
Copy link

gizzye commented Sep 25, 2023

How do i delete this extension it's malware

@hdsenevi
Copy link

For me I had to install both Visual Studio Editor and Visual Studio Code Editor in Unity Package Manager to get this error to go away. Only having Visual Studio Code Editor package in Unity package manger game me the error(s) thats discussed above.

image

@rdvansloten
Copy link

For those still struggling with this on Mac (might work for Windows, idk):

  • Download .NET 7.0: https://dotnet.microsoft.com/en-us/download and install
  • In Visual Studio Code, go to Extensions and install C# Dev Kit, C# and .NET Runtime Install Tool
  • In Unity, go to Package Manager and remove "Visual Studio Code Editor"
  • In Unity, go to Package Manager and make sure "Visual Studio Editor" (not CODE Editor) is installed and version 2.0.21
  • Close Visual Studio Code and reopen

@mcclure
Copy link

mcclure commented Sep 29, 2023

DONT forget to restart Unity after plug-ins updated.

I was struggling horribly with this, and this turned out to be what I was missing. I removed Visual Studio Code Editor, and added Visual Studio Editor*, and it was continuing to generate the project xml files with the bad <TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion> xml no matter how many times I regenerated them. After reading this comment I exited and reopened Unity and did a regenerate and THIS time it generated with a good <TargetFrameworkVersion>.

This is very confusing and the error messages are pretty unhelpful! :(

* Also at this step, after installing Visual Studio Editor and based on a comment on a forum, I went into the Player settings and changed the API Compatibility Level from ".NET Framework" to ".NET Standard 2.1". I do not know if this step did anything at all, but if it did, it had no effect until I restarted Unity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-unity Unity support enhancement New feature or request
Projects
None yet
Development

No branches or pull requests