Files
LanMountainDesktop/docs/Plugins develop/01-快速开始/01-开发环境准备.md
2026-04-13 19:54:37 +08:00

221 lines
5.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 01-开发环境准备
在开始开发阑山桌面插件之前,你需要准备好开发环境。本指南将带你完成所有必要的安装和配置。
---
## ✅ 系统要求
### 支持的操作系统
| 操作系统 | 版本要求 | 备注 |
|---------|---------|------|
| **Windows** | Windows 10 版本 1809 或更高 | 推荐开发平台 |
| **Windows** | Windows 11 | 最佳体验 |
| **Linux** | Ubuntu 20.04+ / Debian 10+ | 支持开发和运行 |
| **macOS** | macOS 12+ | 支持开发和运行 |
### 硬件要求
- **处理器**x64 或 ARM64 架构
- **内存**:至少 4GB RAM推荐 8GB
- **磁盘空间**:至少 2GB 可用空间
---
## 🛠️ 安装 .NET SDK
阑山桌面插件基于 **.NET 10** 开发,你需要安装对应版本的 SDK。
### 下载安装
1. 访问 [.NET 10 下载页面](https://dotnet.microsoft.com/download/dotnet/10.0)
2. 下载适合你操作系统的 SDK 安装包
3. 运行安装程序,按提示完成安装
### 验证安装
打开终端PowerShell、CMD 或 Bash运行以下命令
```powershell
# 检查 .NET SDK 版本
dotnet --version
```
**预期输出示例:**
```
10.0.100
```
⚠️ **如果版本低于 10.0**,请重新下载安装最新版 .NET 10 SDK。
---
## 💻 安装 IDE集成开发环境
你可以选择以下任一 IDE 进行开发:
### 选项 1Visual Studio 2022推荐 Windows 用户)
**优点:** 功能最全,调试体验最佳
1. 下载 [Visual Studio 2022](https://visualstudio.microsoft.com/vs/)
2. 安装时选择以下工作负载:
-**.NET 桌面开发**
-**Avalonia UI 开发**(可选,如需 Avalonia 设计器)
### 选项 2JetBrains Rider跨平台推荐
**优点:** 跨平台智能提示强大Avalonia 支持好
1. 下载 [Rider](https://www.jetbrains.com/rider/)
2. 安装后打开,会自动检测 .NET SDK
### 选项 3Visual Studio Code轻量级
**优点:** 免费,轻量,插件丰富
1. 下载 [VS Code](https://code.visualstudio.com/)
2. 安装以下扩展:
- **C# Dev Kit**Microsoft 官方)
- **Avalonia for VS Code**(可选)
---
## 📦 安装插件模板
阑山桌面提供了官方的 `dotnet new` 模板,帮助你快速创建插件项目。
### 安装模板
```powershell
# 安装最新版插件模板
dotnet new install LanMountainDesktop.PluginTemplate
```
**成功提示:**
```
模板名 短名称 语言 标签
------------------------------------- ---------- ---- ------------
LanMountainDesktop Plugin lmd-plugin C# LanMountainDesktop/Plugin
```
### 验证安装
```powershell
# 列出已安装的模板,查找 lmd-plugin
dotnet new list | findstr lmd
```
Linux/macOS
```bash
dotnet new list | grep lmd
```
---
## 🎮 获取宿主应用
插件需要在阑山桌面宿主中运行,你需要获取宿主应用:
### 方式 1下载 Release 版本(推荐)
1. 访问 GitHub Releases 页面
2. 下载最新版本的安装包(.exe / .deb / .dmg
3. 安装并运行阑山桌面
### 方式 2从源码构建
如果你想调试宿主或了解内部机制:
```powershell
# 克隆仓库
git clone https://github.com/your-org/LanMountainDesktop.git
cd LanMountainDesktop
# 还原依赖
dotnet restore
# 构建项目
dotnet build LanMountainDesktop.slnx -c Debug
# 运行宿主
dotnet run --project LanMountainDesktop/LanMountainDesktop.csproj
```
---
## 🔍 环境验证清单
在继续之前,请确认以下检查项都已完成:
| 检查项 | 验证命令 | 预期结果 |
|-------|---------|---------|
| ✅ .NET SDK 版本 | `dotnet --version` | 10.0.xxx |
| ✅ 模板已安装 | `dotnet new list \| findstr lmd` | 显示 lmd-plugin |
| ✅ IDE 可创建项目 | 在 IDE 中新建项目 | 能看到 C# 项目模板 |
| ✅ 宿主可运行 | 双击 LanMountainDesktop.exe | 应用正常启动 |
---
## ⚠️ 常见问题
### 问题 1dotnet 命令找不到
**现象:** 运行 `dotnet` 提示不是内部或外部命令
**解决:**
1. 确认 .NET SDK 已正确安装
2. 重启终端或 IDE
3. 检查环境变量 PATH 是否包含 `C:\Program Files\dotnet\`
### 问题 2模板安装失败
**现象:** `dotnet new install` 报错或卡住
**解决:**
1. 检查网络连接(需要访问 nuget.org
2. 尝试指定版本号:
```powershell
dotnet new install LanMountainDesktop.PluginTemplate::1.0.0
```
3. 清除模板缓存后重试:
```powershell
dotnet new uninstall LanMountainDesktop.PluginTemplate
dotnet new install LanMountainDesktop.PluginTemplate
```
### 问题 3SDK 版本不匹配
**现象:** 构建时提示 SDK 版本不符合 global.json 要求
**解决:**
1. 检查项目根目录的 `global.json` 文件
2. 安装对应版本的 .NET SDK
3. 或使用以下命令使用已安装的版本:
```powershell
dotnet new globaljson --sdk-version 10.0.100 --roll-forward latestFeature
```
---
## 🎯 下一步
环境准备完成!接下来:
👉 **[02-三分钟创建第一个插件](02-三分钟创建第一个插件.md)** - 立即开始创建你的第一个插件!
---
## 📚 参考资源
- [.NET 10 下载](https://dotnet.microsoft.com/download/dotnet/10.0)
- [Visual Studio 2022](https://visualstudio.microsoft.com/vs/)
- [JetBrains Rider](https://www.jetbrains.com/rider/)
- [VS Code](https://code.visualstudio.com/)
- [Avalonia UI 文档](https://docs.avaloniaui.net/)
---
*最后更新2026年4月*