0

I'm trying to run a simple script for unity

public class BirdScript : MonoBehaviour
{
    public Rigidbody2D myRigidbody;

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space) == true)
        {
            myRigidbody.velocity = Vector2.up * 10;
        }

    }
}

But VSC fails to restore the solution with this error

2023-12-16 10:46:02.365 [info] No .NET SDKs were found.

Download a .NET SDK: https://aka.ms/dotnet-download

Learn about SDK resolution: https://aka.ms/dotnet/sdk-not-found

2023-12-16 10:46:02.367 [info] Additional information of .NET SDKs for diagnostic global.json file: Not found

Host: Version: 6.0.11 Architecture: x64 Commit: 943474ca16

.NET SDKs installed: No SDKs were found.

.NET runtimes installed: Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Download .NET: https://aka.ms/dotnet-download

Learn about .NET Runtimes and SDKs: https://aka.ms/dotnet/runtimes-sdk-info

2023-12-16 10:46:02.381 [info] Project system initialization finished. 0 project(s) are loaded, and 1 failed to load.

I've tried deleting all my extensions and re-installing them and also running the C# Dev Kit with Pre-Release version but nothing seems to work. Any ideas?

I have SDK installed with where.exe dotnet showing me C:\Program Files\dotnet\dotnet.exe (also deleted the x64 one)

Here it's visible that SDK is already installed winget install Microsoft.DotNet.SDK.8 Found an existing package already installed. Trying to upgrade the installed package...

Here is the solution that I did

First i followed these steps from reddit

Uninstalled the Unity package named "Visual Studio Code Editor"

Installed the Unity package named "Visual Studio Editor"

Deleted all project filed (all the .csproj and .sln) from my project folder

Selected Visual Studio Code in the external programs in Unity the first two boxes was checked and clicked to regenerate project files.

Removed all the settings related to the C# and Unity extensions from VS Code

Uninstalled all versions of SDK from my computer (you might need to close VS Code and Unity).

Removed all the PATH windows environment variables related to dotnet

Uninstalled Visual Studio and reinstalled (I think you should look the version of Visual Studio related to your Unity version). I only installed two modules from Visual Studio: "Game development with Unity" and ".Net desktop development".

Restarted my computer and everything worked.

After that I did

winget install Microsoft.DotNet.SDK.8 

After this the project loaded

1 Answer 1

1

You don't have .NET SDK installed only a runtime. To solve this you need to do one of the following:

Winget

  • Run this command:
winget install Microsoft.DotNet.SDK.8
  • Restart Visual Studio Code
  • Try to run a simple C# project to test it

Visual Studio Installer

If you already have Visual Studio 2022 (yes, the classic one, not VS Code), you can modify its components which you can use from VS Code

  • Find Visual Studio Installer in the Start Menu and open it
  • Click Modify next to Visual Studio Community 2022
  • At the top select Individual Components
  • Search for .NET SDK
  • Tick checkbox next to .NET SDK, for me it was the 9th option from the top because the search contains also other similary named items
  • Click Modify in the bottom right corner
  • Wait for the modification to complete
  • Restart VS Code
  • Try to run a simple C# project to test it

Visual Studio Installer (Alternative)

  • Find Visual Studio Installer in the Start Menu and open it
  • Click Modify next to Visual Studio Community 2022
  • At the top select Workloads
  • Find the category Desktop & Mobile, it should be 2nd from the top
  • Tick checkbox next to .NET desktop development
  • Click Modify in the bottom right corner
  • Wait for the modification to complete
  • Restart VS Code
  • Try to run a simple C# project to test it
Sign up to request clarification or add additional context in comments.

Comments

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.