> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devin.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Windows 支持

> 通过蓝图和会话在 Windows 上运行 Devin。

Devin 支持将 Windows 用作构建和会话平台。Windows 环境与 Linux 一样使用 bash shell (Git Bash) ，因此大多数蓝图命令无需修改即可在这两个平台上运行。

<Warning>
  Windows 支持目前仅面向有限用户开放。如果你有兴趣试用 Devin 的 Windows 支持，请[联系我们](https://cognition.com/contact)了解更多信息并获取访问权限。
</Warning>

<div id="how-it-works">
  ## 工作原理
</div>

Windows 支持与 Linux 一样，基于同一套[声明式配置](/zh/onboard-devin/environment/blueprints)系统。关键区别在于蓝图中的 `runs-on` 字段，它会告诉 Devin 在哪个平台上构建和运行。

由于两个平台都使用 bash，你可以在 Linux 和 Windows 上编写相同的 shell 命令。主要区别在于文件系统结构以及可用的包管理器：

| 方面     | Linux (默认)            | Windows                                    |
| ------ | --------------------- | ------------------------------------------ |
| 主目录    | `/home/ubuntu`        | `/c/Users/Administrator`                   |
| 代码仓库目录 | `~/repos/<repo-name>` | `/c/Users/Administrator/repos/<repo-name>` |
| 包管理器   | `apt-get`             | `choco` 或直接下载安装程序                          |

<div id="writing-windows-blueprints">
  ## Windows 蓝图编写
</div>

<div id="single-platform-blueprint">
  ### 单平台蓝图
</div>

如果你的代码仓库仅针对 Windows，请在顶层使用 `runs-on: windows`：

```yaml theme={null}
runs-on: windows

initialize:
  - name: "Install Node.js"
    uses: github.com/actions/setup-node@v4
    with:
      node-version: "20"

  - name: "Install build tools"
    run: |
      choco install visualstudio2022buildtools -y
      choco install python --version=3.12 -y

maintenance: |
  npm install

knowledge:
  - name: lint
    contents: npm run lint
  - name: test
    contents: npm test
  - name: build
    contents: npm run build
```

<div id="multi-platform-blueprint">
  ### 多平台蓝图
</div>

要同时在 Linux 和 Windows 上构建同一个代码仓库，请将每个平台分别写成独立的 YAML 文档，并用 `---` 分隔。每个文档都声明自己的 `runs-on` 标签。有关这种格式的更多背景信息，请参阅蓝图指南中的 [多文档 YAML](/zh/onboard-devin/environment/blueprints#blueprint-sections) 提示框。

```yaml theme={null}
runs-on: default
initialize: |
  curl -LsSf https://astral.sh/uv/install.sh | sh
  apt-get update && apt-get install -y build-essential

maintenance: |
  uv sync

knowledge:
  - name: test
    contents: uv run pytest

---
runs-on: windows
initialize: |
  choco install python --version=3.12 -y

maintenance: |
  uv sync

knowledge:
  - name: test
    contents: uv run pytest
```

每个文档都会为对应平台生成单独的快照构建。会话会从该平台专用的快照启动。

<Warning>
  顶层 YAML 必须是映射，而不能是序列。如果把上面的示例写成单个列表 (`- runs-on: default` / `- runs-on: windows`) ，后端会拒绝，并返回 `Invalid YAML: each YAML document must be a mapping, not a sequence; use '---' to separate multiple blocks`。请使用上面所示的 `---` 分隔符。
</Warning>

<div id="the-runs-on-field">
  ## `runs-on` 字段
</div>

`runs-on` 字段对应于你账户中已注册的一项机器配置：

| 值                    | 平台           |
| -------------------- | ------------ |
| `default` or `linux` | Linux (默认平台) |
| `windows`            | Windows      |

你可以将 `runs-on` 指定为字符串或列表：

```yaml theme={null}
# 单个平台
runs-on: windows

# 在同一块中指定多个平台（每个平台运行相同的命令）
runs-on: [default, windows]
```

当一个块列出多个平台时，构建系统会使用相同的命令，为每个平台创建一个快照。

<Warning>
  列表语法会在列表中的每个平台上运行完全相同的命令。只有在命令确实支持跨平台时才应使用它 (例如 `npm install`、`uv sync`) 。对于平台专用命令 (例如 Linux 上的 `apt-get` 或 Windows 上的 `choco`) ，请改用[多文档格式](#multi-platform-blueprint)——每个平台对应一个文档，并使用 `---` 分隔。
</Warning>

<div id="usage-and-cost">
  ## 用量和成本
</div>

与同等的 Linux 会话相比，Windows 会话消耗的用量 (ACU 或配额) 大约**高出 9%**。有关用量如何计量的详细信息，请参阅[用量](/zh/admin/billing/usage#windows-sessions)。

<div id="windows-session-behavior">
  ## Windows 会话的行为
</div>

<div id="shell">
  ### Shell
</div>

Windows 会话默认使用 **Git Bash** 作为 shell，也就是 Linux 上使用的同一种 bash shell。标准 bash 语法在两个平台上都通用：

```yaml theme={null}
- run: |
    export MY_VAR="hello"
    echo $MY_VAR
```

<div id="paths">
  ### 路径
</div>

Windows 使用 Git Bash 的路径格式 (`/c/...`，而不是 `C:\...`) ：

```yaml theme={null}
# Linux 路径
- run: cp config.json ~/.config/myapp/config.json

# Windows 路径（Git Bash 格式）
- run: cp config.json /c/Users/Administrator/.config/myapp/config.json
```

<div id="secrets">
  ### Secrets
</div>

在会话期间，可通过标准 bash 语法 (`$SECRET_NAME`) 以环境变量的形式使用 Secrets：

```yaml theme={null}
maintenance:
  - name: "Configure registry"
    run: |
      npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
```

<div id="file-attachments">
  ### 文件附件
</div>

在 Windows 上，上传的文件会保存到 `/c/Users/Administrator/.files/`，而不是 `/home/ubuntu/.files/`。

<div id="computer-use">
  ### Computer Use
</div>

[Computer Use](/zh/work-with-devin/computer-use) 在 Windows 会话中已获全面支持。Devin 可使用带有 Chrome、鼠标和键盘访问权限的 Windows 桌面环境，因此既能测试 Web 应用，也能测试 Windows 原生桌面应用程序 (例如 WPF 和 WinForms 应用) ，并记录测试会话。

<div id="blueprint-tips-for-windows">
  ## 适用于 Windows 的蓝图提示
</div>

<div id="installing-tools">
  ### 安装工具
</div>

使用 `choco` (Chocolatey) 或直接下载脚本：

```yaml theme={null}
initialize:
  - name: "Install Chocolatey packages"
    run: |
      choco install git -y
      choco install nodejs-lts -y
      choco install python --version=3.12 -y
      choco install dotnet-sdk -y
```

<div id="common-patterns">
  ### 常见模式
</div>

**.NET 项目：**

```yaml theme={null}
runs-on: windows

initialize:
  - name: "Install .NET SDK"
    run: |
      choco install dotnet-sdk -y

maintenance: |
  dotnet restore

knowledge:
  - name: build
    contents: dotnet build
  - name: test
    contents: dotnet test
  - name: lint
    contents: dotnet format --verify-no-changes
```

**Visual Studio / C++ 项目：**

```yaml theme={null}
runs-on: windows

initialize:
  - name: "Install Visual Studio Build Tools"
    run: |
      choco install visualstudio2022buildtools -y
      choco install visualstudio2022-workload-vctools -y

maintenance: |
  msbuild /t:Restore MySolution.sln

knowledge:
  - name: build
    contents: msbuild MySolution.sln /p:Configuration=Release
  - name: test
    contents: vstest.console.exe bin/Release/Tests.dll
```
