You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity & C# Dev Kit解决方案无法还原的问题与解决方法

Unity脚本开发中VS Code无法还原解决方案的问题与解决步骤

问题场景

我尝试运行一个简单的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;
        }

    }
}

报错信息

VS Code无法还原解决方案,报错日志如下:

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.

无效尝试

  • 卸载并重新安装所有VS Code扩展
  • 使用C# Dev Kit的预发布版本
  • 确认where.exe dotnet能找到SDK路径,且winget显示SDK已安装,但问题依旧

最终解决步骤

第一步:按照Reddit步骤操作

  • 卸载Unity中的Visual Studio Code Editor包
  • 安装Unity中的Visual Studio Editor包
  • 删除项目文件夹内所有项目文件(包括所有.csproj和.sln文件)
  • 在Unity的外部程序设置中选择Visual Studio Code,勾选前两个选项后点击「重新生成项目文件」
  • 删除VS Code中所有与C#、Unity扩展相关的设置
  • 卸载电脑上所有版本的SDK(操作前需关闭VS Code和Unity)
  • 删除Windows环境变量中所有与dotnet相关的PATH条目
  • 卸载并重新安装Visual Studio(需选择与Unity版本匹配的Visual Studio版本),仅安装「使用Unity进行游戏开发」和「.NET桌面开发」两个模块
  • 重启电脑

第二步:安装指定.NET SDK

执行以下命令安装.NET SDK 8:

winget install Microsoft.DotNet.SDK.8

完成以上操作后,项目成功加载。

内容的提问来源于stack exchange,提问作者Scarga

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 03:01:00