<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Infrastructure as Code | The .NET Blog</title><link>https://thedotnetblog.com/zh/tags/infrastructure-as-code/</link><description>Articles, tutorials and insights from the .NET community.</description><generator>Hugo</generator><language>zh</language><managingEditor>@thedotnetblog (The .NET Blog)</managingEditor><webMaster>@thedotnetblog</webMaster><lastBuildDate>Tue, 21 Apr 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://thedotnetblog.com/zh/tags/infrastructure-as-code/index.xml" rel="self" type="application/rss+xml"/><item><title>azd + GitHub Copilot：AI 驱动的项目设置和智能错误修复</title><link>https://thedotnetblog.com/zh/posts/emiliano-montesdeoca/azd-copilot-integration-ai-setup-troubleshooting/</link><pubDate>Tue, 21 Apr 2026 00:00:00 +0000</pubDate><author>Emiliano Montesdeoca</author><guid>https://thedotnetblog.com/zh/posts/emiliano-montesdeoca/azd-copilot-integration-ai-setup-troubleshooting/</guid><description>Azure Developer CLI 现已与 GitHub Copilot 集成，可以生成项目基础架构并修复部署错误——无需离开终端。</description><content:encoded>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;本文为自动翻译。如需阅读英文原文，请&lt;a href="https://thedotnetblog.com/zh/posts/emiliano-montesdeoca/azd-copilot-integration-ai-setup-troubleshooting/"&gt;点击这里&lt;/a&gt;。&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;你是否有过这样的经历：想把现有应用部署到 Azure，却盯着空白的 &lt;code&gt;azure.yaml&lt;/code&gt; 发呆，想不起来 Express API 到底该用 Container Apps 还是 App Service？这种时刻即将成为历史。&lt;/p&gt;
&lt;p&gt;Azure Developer CLI（&lt;code&gt;azd&lt;/code&gt;）现已与 GitHub Copilot 以两种实用的方式集成：&lt;code&gt;azd init&lt;/code&gt; 时的 AI 辅助项目脚手架，以及部署失败时的智能错误排查。两项功能都完全在终端内运行——正是我想要的方式。&lt;/p&gt;
&lt;h2 id="在-azd-init-中使用-copilot-设置"&gt;在 azd init 中使用 Copilot 设置&lt;/h2&gt;
&lt;p&gt;运行 &lt;code&gt;azd init&lt;/code&gt; 时，现在会出现&amp;quot;Set up with GitHub Copilot (Preview)&amp;ldquo;选项。选择它，Copilot 会分析你的代码库，根据实际代码生成 &lt;code&gt;azure.yaml&lt;/code&gt;、基础架构模板和 Bicep 模块。&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;azd init
# 选择：&amp;#34;Set up with GitHub Copilot (Preview)&amp;#34;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;前提条件：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;azd 1.23.11 或更高版本&lt;/strong&gt; — 用 &lt;code&gt;azd version&lt;/code&gt; 检查，或用 &lt;code&gt;azd update&lt;/code&gt; 更新&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;有效的 GitHub Copilot 订阅&lt;/strong&gt;（Individual、Business 或 Enterprise）&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GitHub CLI（&lt;code&gt;gh&lt;/code&gt;）&lt;/strong&gt; — 必要时 &lt;code&gt;azd&lt;/code&gt; 会提示登录&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;我觉得真正实用的是它能双向工作。从零开始构建？Copilot 从一开始就帮你配置正确的 Azure 服务。有现有应用想部署？把 Copilot 指向它，无需重构代码即可生成配置。&lt;/p&gt;
&lt;h3 id="它实际做什么"&gt;它实际做什么&lt;/h3&gt;
&lt;p&gt;假设你有一个 Node.js Express API，依赖 PostgreSQL。不必手动在 Container Apps 和 App Service 之间抉择，也不必从零编写 Bicep，Copilot 检测到你的技术栈后会生成：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;包含正确 &lt;code&gt;language&lt;/code&gt;、&lt;code&gt;host&lt;/code&gt; 和 &lt;code&gt;build&lt;/code&gt; 设置的 &lt;code&gt;azure.yaml&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Azure Container Apps 的 Bicep 模块&lt;/li&gt;
&lt;li&gt;Azure Database for PostgreSQL 的 Bicep 模块&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;并在做任何更改前运行预检——验证 git 工作目录是否干净，提前请求 MCP 服务器工具的授权。一切都在你知情的情况下进行。&lt;/p&gt;
&lt;h2 id="copilot-驱动的错误排查"&gt;Copilot 驱动的错误排查&lt;/h2&gt;
&lt;p&gt;部署错误无可避免。缺少参数、权限问题、SKU 可用性问题——而错误信息很少告诉你真正需要知道的那一件事：&lt;em&gt;如何修复&lt;/em&gt;。&lt;/p&gt;
&lt;p&gt;没有 Copilot 时的循环：复制错误 → 搜索文档 → 读三篇不相关的 Stack Overflow 回答 → 运行一些 &lt;code&gt;az&lt;/code&gt; CLI 命令 → 重试并祈祷。有了集成在 &lt;code&gt;azd&lt;/code&gt; 中的 Copilot，这个循环消失了。任何 &lt;code&gt;azd&lt;/code&gt; 命令失败时，它会立即提供四个选项：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Explain&lt;/strong&gt; — 用通俗语言解释出了什么问题&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Guidance&lt;/strong&gt; — 逐步修复指导&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Diagnose and Guide&lt;/strong&gt; — 完整分析 + Copilot 应用修复（经你批准）+ 可选重试&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Skip&lt;/strong&gt; — 自己处理&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;关键在于：Copilot 已经了解你的项目、失败的命令和错误详情。它的建议针对&lt;em&gt;你的具体情况&lt;/em&gt;，而非泛泛的文档。&lt;/p&gt;
&lt;h3 id="设置默认行为"&gt;设置默认行为&lt;/h3&gt;
&lt;p&gt;如果你总是选择同一个选项，可以跳过交互式提示：&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;azd config set copilot.errorHandling.category troubleshoot
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;可选值：&lt;code&gt;explain&lt;/code&gt;、&lt;code&gt;guidance&lt;/code&gt;、&lt;code&gt;troubleshoot&lt;/code&gt;、&lt;code&gt;fix&lt;/code&gt;、&lt;code&gt;skip&lt;/code&gt;。还可以启用自动修复和重试：&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;azd config set copilot.errorHandling.fix allow
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;随时重置为交互模式：&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;azd config unset copilot.errorHandling.category
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id="总结"&gt;总结&lt;/h2&gt;
&lt;p&gt;这正是真正有价值的 Copilot 集成。运行 &lt;code&gt;azd update&lt;/code&gt; 获取最新版本，在下一个项目中试试 &lt;code&gt;azd init&lt;/code&gt;。&lt;/p&gt;
&lt;p&gt;阅读&lt;a href="https://devblogs.microsoft.com/azure-sdk/azd-copilot-integration/"&gt;原文公告&lt;/a&gt;。&lt;/p&gt;</content:encoded></item></channel></rss>