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

使用dotnet创建的NUnit项目无法在Visual Studio中打开的问题

问题:Visual Studio无法打开dotnet创建的NUnit项目

我是手动测试工程师,正在学习基于C#.NET的Playwright自动化测试。已安装Visual Studio社区版和.NET 8.0 SDK,环境变量也按教程配置完成。使用命令dotnet new nunit -n PlayWrightPracticeProject创建项目后,在Visual Studio中打开时弹出错误:

The selected file cannot be opened as a solution or project. Please select a solution file or a project file.

where.exe dotnet显示路径为C:\Program Files\dotnet\dotnet.exe,dotnet --info输出如下:

.NET SDK:
 Version:           8.0.202
 Commit:            25674bb2f4
 Workload version:  8.0.200-manifests.4e94be9c

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22631
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.202\

.NET workloads installed:
There are no installed workloads to display.

Host:
  Version:      8.0.3
  Architecture: x64
  Commit:       9f4b1f5d66

.NET SDKs installed:
  8.0.202 [C:\Program Files\dotnet\sdk]

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

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found
解决方案
  • 选择正确的文件打开:不要直接打开项目文件夹,进入PlayWrightPracticeProject目录,找到后缀为.csproj的项目文件,通过Visual Studio的「文件→打开→项目/解决方案」选择该文件,或直接双击打开。
  • 补全Visual Studio工作负载:打开Visual Studio安装器,确认已安装.NET桌面开发和ASP.NET和Web开发工作负载,NUnit项目依赖这些组件才能被正常识别。
  • 生成并关联解决方案文件:若项目无.sln文件,打开命令行进入项目目录,依次执行以下命令:
    dotnet new sln
    dotnet sln add .\PlayWrightPracticeProject.csproj
    
    之后打开生成的.sln文件即可。
  • 验证项目完整性:进入项目目录执行dotnet build,若能成功编译,说明项目本身无问题,问题出在Visual Studio的打开方式或组件缺失。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 04:56:09