дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-03 16:51:16 +02:00
docs(csharp): document Project view .NET entry points and Unity Editor attach (#7414)
Documents the .NET solution and project entry points in the Project view and attaching to the Unity Editor. Closes #7410 Co-authored-by: wildcatDownstairs <[email protected]>
Цей коміт міститься в:
1 джерело
c319656529
коміт
0f78b845e6
4 files changed
+64
-28
No files matched your search
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "C# and .NET"
|
||||
description: "C# with the Roslyn language server or csharp-ls, F# with FsAutoComplete, the .NET tool window for builds, NuGet packages and tests, and debugging with netcoredbg."
|
||||
description: "C# with the Roslyn language server or csharp-ls, F# with FsAutoComplete, solutions and projects in the Project view, builds, NuGet packages and tests, and debugging with netcoredbg."
|
||||
---
|
||||
|
||||
OpenIDEA supports C# (`.cs`, `.csx`) through Microsoft's [Roslyn language server](https://github.com/dotnet/roslyn) or [csharp-ls](https://github.com/razzmatazz/csharp-language-server), and F# (`.fs`, `.fsi`, `.fsx`) through [FsAutoComplete](https://github.com/ionide/FsAutoComplete). All of them are installed as .NET tools, and both languages debug with [netcoredbg](https://github.com/Samsung/netcoredbg). Builds, NuGet packages and tests go through the `dotnet` CLI. For other languages, see the [support matrix](/en/languages/index).
|
||||
@@ -37,19 +37,22 @@ Before it installs csharp-ls or FsAutoComplete, the IDE compares the newest SDK
|
||||
|
||||
A `roslyn-language-server`, `csharp-ls`, `fsautocomplete` or `netcoredbg` already on your `PATH` (for example a global `dotnet tool install --global csharp-ls`) is used as is.
|
||||
|
||||
## The .NET tool window
|
||||
## Solutions and projects
|
||||
|
||||
The **.NET** tool window (on the right) works with the `.csproj`, `.fsproj` and `.vbproj` projects in the project folder, including the projects listed in `.sln` and `.slnx` solutions and their project references. Open it with the **.NET Workspace** action from **Find Action…** (`⌘⇧A` / `Ctrl+Shift+A`). **Reload .NET Workspace** scans the folder again.
|
||||
The **Project** tool window lists the .NET solutions and projects it finds, without a manual reload. Each solution is a `Solution '<name>'` node with its projects under it, and a project that is in no solution is a node of its own, above the project folder. Only solution and project files directly in a content root are listed this way; .NET code in subfolders stays in its folders. While the workspace is being scanned, or when the scan failed, a **.NET** node above the project folder shows that in grey text.
|
||||
|
||||
For the selected project you can:
|
||||
Right-click a solution (`.sln`, `.slnx`) or a project (`.csproj`, `.fsproj`, `.vbproj`) to **Build .NET Project**, **Restore .NET Project** or **Clean .NET Project**. The same actions are in **Find Action…** (`⌘⇧A` / `Ctrl+Shift+A`) and act on the file selected in the Project view, else the project of the active editor's file, else the first solution. **Reload .NET Workspace** scans the folder again, and **Cancel .NET Operation** stops a running build, restore or clean.
|
||||
|
||||
- Pick the **Configuration** (`Debug` by default) and **Target framework** (for multi-targeted projects).
|
||||
- **Build**, **Restore** and **Clean** it (also available as the **Build .NET Project**, **Restore .NET Project** and **Clean .NET Project** actions). Output appears in the **Output** section.
|
||||
- Browse its **NuGet packages**, including transitive ones, search your package sources with **Search NuGet packages** (`dotnet package search`), and add, update or remove packages (`dotnet add package` / `dotnet remove package`).
|
||||
- See its **Project references**.
|
||||
- Discover and run tests (see below).
|
||||
Project evaluation uses MSBuild, so the target frameworks, output paths and packages come from what MSBuild computes, including imported properties. Builds use the `Debug` configuration.
|
||||
|
||||
Project evaluation uses MSBuild, so the target frameworks, output paths and packages you see are the ones MSBuild computes, including imported properties.
|
||||
## NuGet packages
|
||||
|
||||
The **NuGet Packages** tool window (bottom) manages the packages of one .NET project, chosen in its **.NET project** list. It stays under the tool window stripe's "…" menu until you first open it; **Refresh NuGet Packages** in **Find Action…** opens it and loads the packages.
|
||||
|
||||
- The installed packages are listed, with transitive ones marked **Transitive**.
|
||||
- **Search** looks in your package sources (`dotnet package search`). **Install / Update** adds the chosen **Version** (`dotnet add package`), and **Versions** lists the versions of one package.
|
||||
- **Remove** removes a direct package (`dotnet remove package`).
|
||||
- The **Output** section shows the command output.
|
||||
|
||||
## Run
|
||||
|
||||
@@ -60,6 +63,8 @@ OpenIDEA creates run configurations for every `.csproj` it finds (also through `
|
||||
|
||||
The **.NET Project** configuration type has fields for the project, **Target framework**, **Launch profile** and **Program arguments**. The project is built before it runs.
|
||||
|
||||
You can also right-click a project file (`.csproj`, `.fsproj` or `.vbproj`) in the Project view and choose **Run '<name>'** or **Debug '<name>'**. That creates a temporary `dotnet run --project <path> --no-launch-profile` configuration, which you can edit or save like any other. Solutions only offer Build, Restore and Clean.
|
||||
|
||||
See [Run configurations](/en/guide/run) for editing and creating configurations.
|
||||
|
||||
## Tests
|
||||
@@ -67,7 +72,7 @@ See [Run configurations](/en/guide/run) for editing and creating configurations.
|
||||
Projects that reference `Microsoft.NET.Test.Sdk`, MSTest, NUnit or xUnit, or set `IsTestProject`, are test projects. Each gets a `dotnet test (<Project>)` configuration.
|
||||
|
||||
- In the editor, test methods marked `[Fact]`, `[Theory]`, `[Test]`, `[TestCase]`, `[TestCaseSource]`, `[TestMethod]` or `[DataTestMethod]` get gutter run icons.
|
||||
- In the .NET tool window, **Discover .NET Tests** lists the tests (`dotnet test --list-tests`), and you can run all of them or one.
|
||||
- **Discover .NET Tests** lists the tests (`dotnet test --list-tests`), and **Run .NET Tests** runs them. Both are in **Find Action…** and use the same project as the build actions above.
|
||||
|
||||
Results appear in the test tree of the Run tool window. The IDE asks VSTest for a TRX report and reads it. Projects on Microsoft.Testing.Platform need the `Microsoft.Testing.Extensions.TrxReport` package for that; **Install TRX reporting** adds it in the version matching the project's testing platform.
|
||||
|
||||
@@ -75,13 +80,14 @@ See [Testing](/en/guide/testing) for the test tree and rerunning failed tests.
|
||||
|
||||
## Debugging
|
||||
|
||||
Running a .NET Project configuration with **Debug** builds the project, asks MSBuild for its output assembly (`TargetPath`, in the Debug configuration) and launches it under netcoredbg. If netcoredbg is missing, a notification offers to install it.
|
||||
Running a .NET Project configuration, or a project file from the Project view, with **Debug** builds the project, asks MSBuild for its output assembly (`TargetPath`, in the Debug configuration) and launches it under netcoredbg. If netcoredbg is missing, a notification offers to install it.
|
||||
|
||||
See [Debugging](/en/guide/debugging).
|
||||
|
||||
## Limitations
|
||||
|
||||
- Automatic run configurations are created only for C# projects (`.csproj`). F# and VB projects can be built and tested from the .NET tool window, but you create their run configurations yourself.
|
||||
- Automatic run configurations are created only for C# projects (`.csproj`). F# and VB projects can be built from the Project view and run or debugged from their project file's context menu, but you create saved run configurations for them yourself.
|
||||
- Builds always use the `Debug` configuration; there is no setting to build `Release` from the Project view.
|
||||
- Test configurations run without a debugger; there is no Debug action for .NET tests.
|
||||
- There is no Visual Basic language server.
|
||||
- netcoredbg has no prebuilt download for Windows on Arm.
|
||||
|
||||
@@ -86,9 +86,21 @@ The IDE notices when Unity writes those files and picks them up without reopenin
|
||||
|
||||
**Navigate › Declaration or Usages** on a Unity type such as `MonoBehaviour` opens the decompiled source read-only. Decompiled files are not checked for errors, since they often use a different C# language version than your project.
|
||||
|
||||
## Debugging
|
||||
|
||||
OpenIDEA attaches to a running Unity Editor with the [Unity debugger](https://github.com/Unity-Technologies/vscode-unity-debug) (`unity-debug`).
|
||||
|
||||
1. In Unity, enable **Editor Attaching** (in **External Tools**) and switch the editor to **Debug Mode**.
|
||||
2. In OpenIDEA, choose the **Unity Editor** run configuration, which appears in every Unity project, and click **Debug**. Or run **Attach to Unity Process** from **Find Action…**.
|
||||
3. Pick the editor process in the list that opens (**Refresh** if it is empty) and click **Attach**.
|
||||
|
||||
If the Unity debugger is missing, the popup offers **Install Unity Debugger**; you can also install it in **Settings › Languages & Frameworks › Language Servers**. Outside Windows it needs [Mono](https://www.mono-project.com) with `mono` on `PATH`.
|
||||
|
||||
Breakpoints in your C# scripts work as in any other debug session. Stopping the session disconnects without closing Unity. Only Unity Editor processes are listed; Unity Hub and player builds are not.
|
||||
|
||||
## Limitations
|
||||
|
||||
- OpenIDEA does not generate Unity's C# project files; Unity has to.
|
||||
- There is no Unity debugger integration: you cannot attach to the Unity editor or a player from OpenIDEA.
|
||||
- The debugger attaches to a running Unity Editor only (see above). Attaching to a player build is not supported.
|
||||
- There are no Unity-specific inspections, run configurations or ShaderLab support.
|
||||
- Opening files from Unity works for local projects only, not projects in WSL.
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "C# 与 .NET"
|
||||
description: "使用 Roslyn 语言服务器或 csharp-ls 的 C#、使用 FsAutoComplete 的 F#,用于构建、NuGet 包和测试的 .NET 工具窗口,以及基于 netcoredbg 的调试。"
|
||||
description: "使用 Roslyn 语言服务器或 csharp-ls 的 C#、使用 FsAutoComplete 的 F#,项目视图中的解决方案和项目、构建、NuGet 包和测试,以及基于 netcoredbg 的调试。"
|
||||
---
|
||||
|
||||
OpenIDEA 通过微软的 [Roslyn 语言服务器](https://github.com/dotnet/roslyn)或 [csharp-ls](https://github.com/razzmatazz/csharp-language-server) 支持 C#(`.cs`、`.csx`),通过 [FsAutoComplete](https://github.com/ionide/FsAutoComplete) 支持 F#(`.fs`、`.fsi`、`.fsx`)。它们都以 .NET 工具的形式安装,两种语言的调试都使用 [netcoredbg](https://github.com/Samsung/netcoredbg)。构建、NuGet 包和测试统一走 `dotnet` 命令行。其他语言见[语言支持总览](/zh/languages/index)。
|
||||
@@ -37,19 +37,22 @@ C# 在装了 Roslyn 语言服务器时用它,否则用 csharp-ls。Roslyn 是
|
||||
|
||||
`PATH` 上已有的 `roslyn-language-server`、`csharp-ls`、`fsautocomplete` 或 `netcoredbg`(例如通过 `dotnet tool install --global csharp-ls` 安装的全局工具)会直接使用。
|
||||
|
||||
## .NET 工具窗口
|
||||
## 解决方案和项目
|
||||
|
||||
**.NET** 工具窗口(位于右侧)管理项目文件夹中的 `.csproj`、`.fsproj` 和 `.vbproj` 项目,包括 `.sln`、`.slnx` 解决方案中列出的项目及其项目引用。通过 **查找操作…**(`⌘⇧A` / `Ctrl+Shift+A`)执行 **.NET 工作区** 打开它;**重新加载 .NET 工作区** 会重新扫描文件夹。
|
||||
**项目**工具窗口会列出找到的 .NET 解决方案和项目,无需手动重新加载。每个解决方案是一个 `Solution '<名称>'` 节点,其下是它的项目;不属于任何解决方案的项目单独成一个节点,位于项目文件夹之上。只有直接位于内容根目录的解决方案和项目文件会这样显示,子文件夹中的 .NET 代码仍留在各自的文件夹里。工作区正在扫描或扫描失败时,项目文件夹之上的 **.NET** 节点会用灰色文字显示状态。
|
||||
|
||||
对选中的项目可以:
|
||||
在解决方案(`.sln`、`.slnx`)或项目(`.csproj`、`.fsproj`、`.vbproj`)上右键,可以执行 **构建 .NET 项目**、**还原 .NET 项目**、**清理 .NET 项目**。同样的操作也在 **查找操作…**(`⌘⇧A` / `Ctrl+Shift+A`)中,作用对象依次为:项目视图中选中的文件、当前编辑器文件所在的项目、第一个解决方案。**重新加载 .NET 工作区** 会重新扫描文件夹,**取消 .NET 操作** 会停止正在进行的构建、还原或清理。
|
||||
|
||||
- 选择 **配置**(默认 `Debug`)和 **目标框架**(多目标项目)。
|
||||
- **构建**、**恢复**、**清理**(也可以通过 **构建 .NET 项目**、**还原 .NET 项目**、**清理 .NET 项目** 这几个操作执行),输出显示在 **输出** 区域。
|
||||
- 浏览 **NuGet 包**(包括间接依赖),用 **搜索 NuGet 包** 在已配置的包源中搜索(`dotnet package search`),以及添加、更新或移除包(`dotnet add package` / `dotnet remove package`)。
|
||||
- 查看 **项目引用**。
|
||||
- 发现并运行测试(见下文)。
|
||||
项目信息由 MSBuild 求值得到,因此目标框架、输出路径和包都是 MSBuild 实际计算的结果,包括导入的属性。构建使用 `Debug` 配置。
|
||||
|
||||
项目信息由 MSBuild 求值得到,因此看到的目标框架、输出路径和包都是 MSBuild 实际计算的结果,包括导入的属性。
|
||||
## NuGet 包
|
||||
|
||||
**NuGet 包**工具窗口(位于底部)管理一个 .NET 项目的包,项目在其 **.NET 项目** 列表中选择。第一次打开之前,它收在工具窗口栏的“…”菜单里;在 **查找操作…** 中执行 **刷新 NuGet 包** 会打开它并加载包。
|
||||
|
||||
- 列出已安装的包,间接依赖标有 **间接依赖**。
|
||||
- **搜索** 在已配置的包源中搜索(`dotnet package search`)。**安装 / 更新** 添加所选 **版本**(`dotnet add package`),**版本** 列出某个包的各个版本。
|
||||
- **移除** 移除直接依赖的包(`dotnet remove package`)。
|
||||
- **输出** 区域显示命令输出。
|
||||
|
||||
## 运行
|
||||
|
||||
@@ -60,6 +63,8 @@ C# 在装了 Roslyn 语言服务器时用它,否则用 csharp-ls。Roslyn 是
|
||||
|
||||
**.NET 项目** 运行配置类型包含项目、**目标框架**、**启动配置** 和 **程序实参** 等字段,运行前会先构建项目。
|
||||
|
||||
也可以在项目视图中右键项目文件(`.csproj`、`.fsproj` 或 `.vbproj`),选择 **运行 '<名称>'** 或 **调试 '<名称>'**。这会创建一个临时的 `dotnet run --project <路径> --no-launch-profile` 配置,可以像其他配置一样编辑或保存。解决方案只提供构建、还原和清理。
|
||||
|
||||
运行配置的编辑与新建见[运行配置](/zh/guide/run)。
|
||||
|
||||
## 测试
|
||||
@@ -67,7 +72,7 @@ C# 在装了 Roslyn 语言服务器时用它,否则用 csharp-ls。Roslyn 是
|
||||
引用了 `Microsoft.NET.Test.Sdk`、MSTest、NUnit 或 xUnit,或者设置了 `IsTestProject` 的项目被视为测试项目,每个都会生成一个 `dotnet test (<项目>)` 配置。
|
||||
|
||||
- 在编辑器中,标注了 `[Fact]`、`[Theory]`、`[Test]`、`[TestCase]`、`[TestCaseSource]`、`[TestMethod]` 或 `[DataTestMethod]` 的测试方法在行号栏会显示运行图标。
|
||||
- 在 .NET 工具窗口中,**发现 .NET 测试** 会列出所有测试(`dotnet test --list-tests`),可以全部运行或只运行其中一个。
|
||||
- **发现 .NET 测试** 会列出所有测试(`dotnet test --list-tests`),**运行 .NET 测试** 会运行它们。两者都在 **查找操作…** 中,作用的项目与上面的构建操作相同。
|
||||
|
||||
结果显示在运行工具窗口的测试树中:IDE 让 VSTest 生成 TRX 报告并读取它。基于 Microsoft.Testing.Platform 的项目需要 `Microsoft.Testing.Extensions.TrxReport` 包才能生成报告,**安装 TRX 报告支持** 会按项目所用测试平台的版本添加它。
|
||||
|
||||
@@ -75,13 +80,14 @@ C# 在装了 Roslyn 语言服务器时用它,否则用 csharp-ls。Roslyn 是
|
||||
|
||||
## 调试
|
||||
|
||||
以 **调试** 方式运行 .NET 项目配置时,IDE 会先构建项目,再向 MSBuild 查询输出程序集(Debug 配置下的 `TargetPath`),然后在 netcoredbg 下启动。缺少 netcoredbg 时会弹出通知提供安装。
|
||||
以 **调试** 方式运行 .NET 项目配置或项目视图中的项目文件时,IDE 会先构建项目,再向 MSBuild 查询输出程序集(Debug 配置下的 `TargetPath`),然后在 netcoredbg 下启动。缺少 netcoredbg 时会弹出通知提供安装。
|
||||
|
||||
详见[调试](/zh/guide/debugging)。
|
||||
|
||||
## 已知限制
|
||||
|
||||
- 只有 C# 项目(`.csproj`)会自动生成运行配置。F# 和 VB 项目可以在 .NET 工具窗口中构建和测试,但运行配置需要自己创建。
|
||||
- 只有 C# 项目(`.csproj`)会自动生成运行配置。F# 和 VB 项目可以在项目视图中构建,并通过项目文件的右键菜单运行或调试,但保存的运行配置需要自己创建。
|
||||
- 构建始终使用 `Debug` 配置,项目视图中无法选择构建 `Release`。
|
||||
- 测试配置不带调试器运行,.NET 测试没有调试入口。
|
||||
- 没有 Visual Basic 语言服务器。
|
||||
- netcoredbg 没有 Windows on Arm 的预编译包。
|
||||
|
||||
@@ -86,9 +86,21 @@ Unity 写出这些文件后,IDE 会自动感知并加载,无需重新打开
|
||||
|
||||
在 `MonoBehaviour` 这类 Unity 类型上使用 **导航 › 声明或用法**,会以只读方式打开反编译后的源码。反编译文件不做错误检查,因为它们使用的 C# 语言版本往往和项目不同。
|
||||
|
||||
## 调试
|
||||
|
||||
OpenIDEA 通过 [Unity 调试器](https://github.com/Unity-Technologies/vscode-unity-debug)(`unity-debug`)附加到正在运行的 Unity 编辑器。
|
||||
|
||||
1. 在 Unity 中启用 **Editor Attaching**(位于 **External Tools**),并把编辑器切换到 **Debug Mode**。
|
||||
2. 在 OpenIDEA 中选择 **Unity 编辑器** 运行配置(每个 Unity 项目都会有)并点击 **调试**;或在 **查找操作…** 中执行 **附加到 Unity 进程**。
|
||||
3. 在弹出的列表中选择编辑器进程(列表为空时点 **刷新**),点击 **附加**。
|
||||
|
||||
缺少 Unity 调试器时,弹窗会提供 **安装 Unity 调试器**,也可以在 **设置 › 语言与框架 › 语言服务器** 中安装。在 Windows 以外的系统上还需要 [Mono](https://www.mono-project.com),并确保 `mono` 在 `PATH` 上。
|
||||
|
||||
C# 脚本中的断点与其他调试会话一样工作。停止会话只会断开连接,不会关闭 Unity。列表只包含 Unity 编辑器进程,不包含 Unity Hub 和播放器构建。
|
||||
|
||||
## 限制
|
||||
|
||||
- OpenIDEA 不会生成 Unity 的 C# 项目文件,需要由 Unity 生成。
|
||||
- 没有 Unity 调试集成:无法从 OpenIDEA 附加到 Unity 编辑器或播放器。
|
||||
- 调试器只能附加到正在运行的 Unity 编辑器(见上文),不支持附加到播放器构建。
|
||||
- 没有 Unity 专用的检查、运行配置,也不支持 ShaderLab。
|
||||
- 从 Unity 打开文件只支持本地项目,不支持 WSL 中的项目。
|
||||
Reference in new issue
Заблокувати користувача