概述
了解如何使用 Copilot CLI 中的 GitHub Copilot modernization 插件将 .NET 应用程序迁移到 Azure。
该插件提供一个自治的多代理工作流,用于评估.NET应用程序、生成可执行的现代化计划,并从终端执行迁移(全部)。 它支持Azure迁移、CVE 漏洞修复和应用程序重新架构。
注释
GitHub Copilot CLI 在 GitHub Copilot Pro、GitHub Copilot Pro+、GitHub Copilot Business 和 GitHub Copilot Enterprise 计划中提供。 如果通过组织收到 Copilot,管理员必须在组织设置中启用 Copilot CLI 策略。
你能做什么
| 能力 | Description |
|---|---|
| .NET迁移到 Azure | 评估.NET应用程序并将其迁移到Azure服务(服务总线、Azure SQL、Redis、密钥保管库、Application Insights、托管标识),包括 NuGet 安全审核和 ASP.NET 到Azure迁移 |
| CVE 和漏洞修复 | 扫描和修复 NuGet 依赖项中的 CVE 漏洞 |
| 应用程序重新架构 | 结构性重构,例如将单体应用拆分为微服务、对遗留 UI 进行现代化改造,以及模块提取 |
先决条件
- 安装 Copilot CLI。
- 一个 GitHub Copilot 订阅。 请参阅 Copilot 计划。
安装插件
在终端中,运行
copilot以启动 Copilot CLI。copilot添加市场并安装插件:
copilot plugin marketplace add microsoft/github-copilot-modernization copilot plugin install github-copilot-modernization@github-copilot-modernization通过列出已安装的插件来验证是否已安装插件:
/plugin list应在列表中看到
github-copilot-modernization:modernize。
更新插件
若要在新版本可用时更新插件,请运行:
copilot plugin update github-copilot-modernization@github-copilot-modernization
启动现代化任务
选项 1:直接从代理开始
导航到.NET项目文件夹,并使用现代化代理启动 Copilot CLI:
cd /path/to/your/dotnet-project
copilot --agent=github-copilot-modernization:modernize
选项 2:从 Copilot CLI 内部选择代理
如果已在 Copilot CLI 会话中,请使用 /agent 命令切换到现代化代理:
/agent
从列表中选择github-copilot-modernization:modernize。
Important
在运行任何现代化提示词之前,您必须先选择 github-copilot-modernization:modernize 代理。 如果未选择此代理,Copilot CLI 将使用默认代理,该代理无法使用插件提供的完整多代理业务流程、企业 playbook 支持和专用迁移功能。
运行现代化提示
代理处于活动状态后,请用自然语言描述所需内容:
copilot> modernize my application
或者更具体:
copilot> modernize my .NET application for Azure
copilot> migrate this app from local SQL Server to Azure SQL Database
copilot> fix CVE vulnerabilities in my project
对于无人参与的执行,请使用标志 --allow-all :
copilot --agent=github-copilot-modernization:modernize --allow-all
工作流的工作原理
该插件使用自动运行的三阶段工作流。 无需手动调用每个阶段 , 业务流程协调程序会根据请求处理路由。
阶段 1:评估
- 检测.NET项目结构并使用相应的分析工具。
- 分析依赖项、框架和版本。
- 确定现代化机会和风险。
- 将结果保存到
.github/modernize/assessment/.
阶段 2:规划
- 加载评估结果和企业行动手册约束(如果有)。
- 生成可执行的任务计划。
- 将计划保存到
.github/modernize/<app>/plan.md和tasks.json.
阶段 3:执行
- 根据任务类型将任务路由到专用执行程序代理。
- 每个执行程序都会查询知识库以获取迁移模式。
- 监控进度,并在失败时自动重试。
- 创建详细的按任务划分的提交,供审阅。
业务流程协调程序支持多个入口点,具体取决于你的意图:
| Workflow | 激活时 | 发生的情况 |
|---|---|---|
| 宽泛意图 | 使我的应用程序现代化 | 完整的评估→规划→执行流程 |
| 特定任务 | “从SQL Server迁移到Azure SQL” | 跳过评估,直接进入计划→执行阶段 |
| 执行现有计划 | “执行计划” | 跳过评估和规划,运行现有计划 |
| 无头 | 使用 --allow-all 进行无人值守执行 |
与无用户提示时的宽泛意图相同 |
定义企业现代化策略
组织可以通过 playbook 直接将其现代化意向(目标体系结构、升级标准和合规性策略)嵌入工作流。 此方法可确保每个生成的计划都与企业标准保持一致,而无需手动审查每个决策。
设置行动手册
将 Markdown 文件 .github/modernize/playbook/ 置于项目的目录中。 规划阶段会自动读取此文件夹中的所有 .md 文件,并在生成任务计划之前将其与评估结果合并。
Important
行动手册约束优先于评估建议。 如果 playbook 指定了“使用Azure 服务总线进行消息传递”,则无论评估发现什么,该选择都优先。
可在操作手册中定义的内容
| 策略类型 | 示例 |
|---|---|
| 目标体系结构 | 计算服务(应用服务、AKS、容器应用)、数据库选择(Azure SQL、Cosmos DB)、消息传送平台(服务总线、事件中心) |
| 升级标准 | 目标.NET版本、框架迁移路径 |
| 护栏 | 禁止的技术, 安全要求, 合规性约束, 身份验证标准 |
| 编码标准 | 命名约定、身份验证模式、日志记录框架 |
| 迁移策略 | 范围边界,6R 分类首选项(重新托管与重构与重新架构),分阶段策略 |
示例操作手册
在 .github/modernize/playbook/enterprise-standards.md 创建一个文件:
# Enterprise Modernization Standards
## Target Architecture
- Use Azure Container Apps for microservices deployments
- Use Azure Service Bus for all asynchronous messaging
- Use Azure SQL Database for relational data
- Use Azure Blob Storage for file storage
## Security & Compliance
- All services must authenticate using Managed Identity — no connection strings or passwords in code
- All public endpoints must be behind Azure Front Door
## Guardrails
- Do not use Azure Functions for long-running processes
- All infrastructure must be defined in Bicep
不需要固定的命名或结构 - 业务流程协调程序从其内容推断每个文件的用途。
内置默认值
如果没有 playbook,插件将应用合理的默认值:
- Azure:用于身份验证的托管标识;用于关系型数据的托管数据库服务。
- Messaging:本地消息传送→ Azure 服务总线。
- 基础设施:默认使用 Bicep。
常见场景
Azure迁移
copilot --agent=github-copilot-modernization:modernize
copilot> modernize my .NET application for Azure
从本地SQL Server迁移到Azure SQL
copilot --agent=github-copilot-modernization:modernize
copilot> migrate this app from local SQL Server to Azure SQL Database with managed identity
从文件 I/O 迁移到Azure Blob 存储
copilot --agent=github-copilot-modernization:modernize
copilot> migrate this app from local file I/O to Azure Blob Storage
CVE 和安全修复
copilot --agent=github-copilot-modernization:modernize
copilot> fix CVE vulnerabilities in my project
应用程序重新架构
copilot --agent=github-copilot-modernization:modernize
copilot> rearchitect my monolithic application into microservices
完全现代化
copilot --agent=github-copilot-modernization:modernize
copilot> modernize my application
Troubleshooting
找不到插件
# Verify marketplace is added
copilot plugin marketplace list
# Re-add marketplace if needed
copilot plugin marketplace add microsoft/github-copilot-modernization
# Reinstall
copilot plugin install github-copilot-modernization@github-copilot-modernization
评估失败:找不到任何应用程序
- 验证项目根目录是否包含文件
.csproj.sln。 - 在启动 Copilot CLI 之前,请确保位于正确的目录中。
MCP 服务器问题
该插件使用在其配置中定义的 MCP 服务器。 如果遇到问题,请重新安装插件以重置 MCP 配置。
提供反馈
使用 GitHub Copilot CLI 反馈表单共享有关 GitHub Copilot CLI 的反馈。