Skip to content

Comments

Fix azure-prepare to use azd init --from-code for .NET Aspire projects#957

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/fix-azure-yaml-generation
Draft

Fix azure-prepare to use azd init --from-code for .NET Aspire projects#957
Copilot wants to merge 5 commits intomainfrom
copilot/fix-azure-yaml-generation

Conversation

Copy link
Contributor

Copilot AI commented Feb 18, 2026

The skill was manually generating azure.yaml files for Aspire projects with only name/metadata fields, missing the services section. This caused "Could not find infra\main.bicep" errors since Aspire auto-generates infrastructure from the AppHost.

Changes

  • New dedicated guide (recipes/azd/aspire.md) - Shows correct vs incorrect approach with detection patterns
  • Enhanced detection guidance (generate.md) - Makes Aspire check mandatory first step with grep/find commands
  • Added warnings at key decision points (azure-yaml.md, recipe-selection.md, aspire.md)
  • Test utilities - Added hasServicesSection() and getServiceProject() to validate azure.yaml structure
  • Test coverage - Added integration test for aspire-with-azure-functions sample

Detection Pattern

# Find AppHost projects
find . -name "*.AppHost.csproj"
grep -r "Aspire\.Hosting\|Aspire\.AppHost\.Sdk" . --include="*.csproj"

# If detected, use azd init instead of manual generation
azd init --from-code -e "$ENV_NAME"

Before/After

Before (manual creation):

name: aspire-app
metadata:
  template: azd-init
# Missing services section → deployment fails

After (azd init --from-code):

name: aspire-app
metadata:
  template: azd-init
services:
  app:
    project: ./MyApp.AppHost/MyApp.AppHost.csproj
    host: containerapp

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • centralus-2.in.applicationinsights.azure.com
    • Triggering command: /home/REDACTED/.npm/_npx/6027471c64e54353/node_modules/@azure/mcp-linux-x64/dist/azmcp /home/REDACTED/.npm/_npx/6027471c64e54353/node_modules/@azure/mcp-linux-x64/dist/azmcp server start (dns block)
  • https://api.github.com/user
    • Triggering command: /home/REDACTED/work/GitHub-Copilot-for-Azure/GitHub-Copilot-for-Azure/tests/node_modules/@github/copilot-linux-x64/copilot /home/REDACTED/work/GitHub-Copilot-for-Azure/GitHub-Copilot-for-Azure/tests/node_modules/@github/copilot-linux-x64/copilot --headless --log-level error --stdio (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>azure-prepare skill generates incorrect azure.yaml for .NET Aspire AppHost projects</issue_title>
<issue_description>## Description

When deploying a .NET Aspire application, the azure-prepare skill manually generates an azure.yaml with only name and metadata fields, missing the critical services section that points to the AppHost .csproj. This causes azd up to fail because it cannot find infra/main.bicep — Aspire apps auto-generate infrastructure from the AppHost, so azd must be aware of the AppHost project.

Steps to Reproduce

  1. Clone the dotnet/aspire-samples repo
  2. Navigate to samples/aspire-with-azure-functions
  3. Ask Copilot for Azure to deploy the application
  4. The agent follows the azure-prepare skill's AZD recipe and manually creates azure.yaml:
    name: aspire-with-azure-functions
    metadata:
      template: azd-init
  5. Run azd up — fails with:
    ERROR: failed to compile bicep template: Could not find a part of the path 'infra\main.bicep'
    

Expected Behavior

The azure-prepare skill should detect .NET Aspire AppHost projects (identifiable by Aspire.AppHost.Sdk or Aspire.Hosting.* packages in .csproj files) and use azd init --from-code to generate the correct azure.yaml instead of manually creating one. The correct generated file looks like:

name: aspire-with-azure-functions
services:
  app:
    language: dotnet
    project: ./ImageGallery.AppHost/ImageGallery.AppHost.csproj
    host: containerapp

Root Cause

The azure-prepare skill references (azure-yaml.md, recipe-selection.md, etc.) do not include guidance for .NET Aspire projects, which have a unique deployment model:

  • Infrastructure is auto-generated from the AppHost code at provision time
  • No manual infra/ directory or Bicep files are needed
  • azure.yaml must reference the AppHost .csproj with host: containerapp

The skill's AZD recipe assumes all projects need manually-authored azure.yaml + infra/ artifacts.

Suggested Fix

  1. Add Aspire detection to the scan/analysis phase (look for Aspire.AppHost.Sdk in .csproj files or Aspire.Hosting.* packages)
  2. When an Aspire AppHost is detected, use azd init --from-code -e <env-name> --no-prompt instead of manually generating azure.yaml
  3. Add an Aspire-specific section to the AZD recipe documentation explaining that Aspire apps don't need manual Bicep infrastructure

Environment

  • azd version: 1.23.3
  • OS: Windows
  • Sample: dotnet/aspire-samples/samples/aspire-with-azure-functions
  • Aspire SDK: 13.1.0, .NET 10</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits February 18, 2026 21:47
Co-authored-by: kvenkatrajan <102772054+kvenkatrajan@users.noreply.github.com>
Co-authored-by: kvenkatrajan <102772054+kvenkatrajan@users.noreply.github.com>
Co-authored-by: kvenkatrajan <102772054+kvenkatrajan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix azure.yaml generation for .NET Aspire AppHost projects Fix azure-prepare to use azd init --from-code for .NET Aspire projects Feb 18, 2026
describe("aspire-brownfield", () => {
const ASPIRE_SAMPLES_REPO = "https://github.com/dotnet/aspire-samples.git";

test("generates azure.yaml with services section for Aspire projects", async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeo02 please confirm integration test for brownfield was created correctly

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeo02
Copy link
Collaborator

jeo02 commented Feb 21, 2026

Test Report: agent-metadata-2026-02-21T00-07-18-573Z

Date: 2026-02-21
Duration: ~10-12 minutes (estimated from execution flow)
Status: ✅ PASSED
Confidence: 🟢 HIGH

📝 Test Prompt

Please deploy this application to Azure. Use the eastus2 region. Use my current subscription. This is for a small scale production environment. Use standard SKUs.

📊 Result Summary

Metric Value
Status PASSED
Retries 0
Duration ~720000ms (~720s)
Skill azure-prepare
Task Type Azure Deployment Preparation

🎯 Confidence Level

Overall Confidence: 🟢 HIGH (85%)

Factor Impact
Skill invocation success +25
Infrastructure generation +25
Configuration optimization +20
Environment setup +15

Confidence Indicators:

  • ✅ azure-prepare skill invoked correctly on first attempt
  • ✅ .NET Aspire application detected and analyzed successfully
  • ✅ Deployment plan created at .azure/plan.md
  • azd init --from-code executed successfully
  • ✅ Infrastructure (Bicep) generated to disk
  • ✅ Region configured to eastus2 as requested
  • ✅ SKUs optimized for small-scale production (Standard_LRS, Basic ACR)
  • ✅ Environment values validated

⚠️ Warnings (Non-Blocking)

These issues were detected during execution but did not prevent the task from completing.
They are documented for awareness and potential optimization.

Warning Summary

Category Count Why It Didn't Matter
Tool Errors 3 Failed reads/searches for non-critical paths; agent adapted successfully
Version Warnings 4 azd version outdated warning; functionality unaffected

Warning Details

Tool Errors (Path Not Found)

Why it didn't block success: Agent successfully adapted by using alternative approaches to gather required information.

  • Cannot find path 'Program.cs' - Agent found AppHost.cs instead
  • Path does not exist for functions.module.bicep - Agent found alternative paths
  • error: Parent directory does not exist - Agent created directory and retried successfully

Version Warnings

Why it didn't block success: azd 1.23.3 has all required functionality; 1.23.5 update is cosmetic.

  • WARNING: your version of azd is out of date, you have 1.23.3 and the latest version is 1.23.5
  • ...and 3 more

🎯 Success Artifacts

📄 Generated Files & Reports

Path Type Skill
.azure/plan.md Deployment Plan azure-prepare
samples/aspire-with-azure-functions/azure.yaml AZD Configuration azure-prepare
samples/aspire-with-azure-functions/infra/main.bicep Infrastructure (Bicep) azure-prepare
samples/aspire-with-azure-functions/infra/main.parameters.json Parameters azure-prepare
samples/aspire-with-azure-functions/infra/storage/storage.module.bicep Storage Module azure-prepare
samples/aspire-with-azure-functions/infra/env/env.module.bicep Environment Module azure-prepare
samples/aspire-with-azure-functions/infra/env-acr/env-acr.module.bicep ACR Module azure-prepare
samples/aspire-with-azure-functions/.azure/imagegallery-prod/.env Environment Config azure-prepare

🔧 Configuration Applied

Setting Value Status
Azure Region eastus2
Environment Name imagegallery-prod
Storage SKU Standard_LRS ✅ (optimized)
Container Registry SKU Basic
Deployment Approach AZD + Aspire

🎯 Skills Invoked

Skill Type Category
azure-prepare Custom Azure Deployment

🔧 Tools Invoked

Tool Count Actions
powershell 15x Directory navigation, azd commands, file checks, environment configuration
view 10x File/directory inspection, code analysis
glob 6x File pattern matching (*.csproj, *.sln, *.json, etc.)
create 2x Created .azure/plan.md
edit 2x Updated plan status, optimized storage SKU
report_intent 2x "Preparing Azure deployment", "Analyzing application structure"
azure-subscription_list 1x Subscription enumeration

🔌 Azure MCP Tools Used

Tool Type Category
azure-subscription_list MCP Azure Resource Management

📈 Token Usage

Metric Value
Input Tokens ~8,500 (estimated)
Output Tokens ~3,200 (estimated)
Total Tokens ~11,700 (estimated)

🔐 Azure Authentication

  • Azure CLI: ✅ Authenticated (subscription access verified)

Note: Agent successfully queried subscriptions via MCP tool, confirming active authentication context.

🚀 Further Optimization

Recommended Actions

Priority Action Benefit Effort
🟡 Medium Update azd to 1.23.5 Remove version warnings Low (1 command)
🟢 Low Add explicit subscription parameter Avoid ambiguity in multi-sub environments Low
🟢 Low Pre-validate .NET 10 SDK installation Catch dependency issues earlier Low

Details

  1. Update Azure Developer CLI

    • Run winget upgrade Microsoft.Azd to eliminate version warnings
    • Ensures access to latest features and bug fixes
  2. Explicit Subscription Handling

    • Current approach relies on default subscription
    • Consider adding azd env set AZURE_SUBSCRIPTION_ID <id> for clarity
    • Reduces risk in multi-subscription scenarios
  3. Pre-Flight Dependency Check

    • Validate .NET 10 SDK before azd init
    • Check Docker availability for local testing
    • Add to planning phase checklist

📚 Learnings

What Worked

  • ✅ Skill invocation pattern correct (azure-prepare for deployment tasks)
  • ✅ Plan-first approach successful (created .azure/plan.md before execution)
  • ✅ Agent correctly identified .NET Aspire project type
  • azd init --from-code auto-detected AppHost successfully
  • ✅ Infrastructure generation and SKU optimization completed
  • ✅ Error recovery excellent (adapted to missing files gracefully)
  • ✅ Region and environment configuration applied correctly

Areas for Improvement

  • ⚠️ Multiple failed file reads could be avoided with better path handling
  • ⚠️ Consider checking azd version before execution
  • ⚠️ Subscription confirmation step could be more explicit

Aspire-Specific Learnings

Agent correctly followed Aspire best practices:

  • Used azd init --from-code instead of manual azure.yaml creation
  • Let Aspire AppHost drive infrastructure generation
  • Generated Bicep from AppHost definitions
  • Avoided common "Could not find infra/main.bicep" error

Generated at 2026-02-21T00:17:47Z

@jeo02
Copy link
Collaborator

jeo02 commented Feb 21, 2026

Ran it locally as it placed the test inside of azure-prepare which only lets you run all the azure-prepare tests. (Only deploy lets you run by test name)

@github-actions
Copy link
Contributor

🔍 Token Analysis Report

@github-copilot-for-azure/scripts@1.0.0 tokens
node --import tsx src/tokens/cli.ts compare --base origin/main --head HEAD --markdown

📊 Token Change Report

Comparing origin/mainHEAD

Summary

Metric Value
📈 Total Change +781 tokens (+11%)
Before 7,075 tokens
After 7,856 tokens
Files Changed 5

Changed Files

File Before After Change
plugin/skills/azure-prepare/references/recipes/azd/aspire.md 1,289 1,584 +295 (+23%)
plugin/skills/azure-prepare/references/generate.md 798 965 +167 (+21%)
plugin/skills/azure-prepare/references/recipe-selection.md 706 829 +123 (+17%)
plugin/skills/azure-prepare/references/aspire.md 2,573 2,675 +102 (+4%)
plugin/skills/azure-prepare/references/recipes/azd/azure-yaml.md 1,709 1,803 +94 (+6%)

@github-copilot-for-azure/scripts@1.0.0 tokens
node --import tsx src/tokens/cli.ts check --markdown

📊 Token Limit Check Report

Checked: 391 files
Exceeded: 91 files

⚠️ Files Exceeding Token Limits

File Tokens Limit Over By
.github/skills/file-test-bug/SKILL.md 613 500 +113
.github/skills/sensei/README.md 3428 1000 +2428
.github/skills/sensei/SKILL.md 1958 500 +1458
.github/skills/sensei/references/EXAMPLES.md 3328 1000 +2328
.github/skills/sensei/references/LOOP.md 3441 1000 +2441
.github/skills/sensei/references/SCORING.md 1690 1000 +690
.github/skills/sensei/references/TOKEN-INTEGRATION.md 1094 1000 +94
.github/skills/skill-authoring/SKILL.md 732 500 +232
plugin/skills/appinsights-instrumentation/SKILL.md 952 500 +452
plugin/skills/azure-ai/SKILL.md 835 500 +335
plugin/skills/azure-aigateway/SKILL.md 6329 500 +5829
plugin/skills/azure-compliance/SKILL.md 1238 500 +738
plugin/skills/azure-compliance/references/azqr-recommendations.md 1447 1000 +447
plugin/skills/azure-compliance/references/azqr-remediation-patterns.md 1987 1000 +987
plugin/skills/azure-compliance/references/azure-keyvault-expiration-audit.md 1286 1000 +286
plugin/skills/azure-compliance/references/azure-quick-review.md 1268 1000 +268
plugin/skills/azure-cost-optimization/SKILL.md 3456 500 +2956
plugin/skills/azure-deploy/SKILL.md 961 500 +461
plugin/skills/azure-deploy/references/pre-deploy-checklist.md 1004 1000 +4
plugin/skills/azure-deploy/references/troubleshooting.md 1123 1000 +123
plugin/skills/azure-diagnostics/SKILL.md 876 500 +376
plugin/skills/azure-kusto/SKILL.md 2167 500 +1667
plugin/skills/azure-messaging/SKILL.md 857 500 +357
plugin/skills/azure-messaging/references/service-troubleshooting.md 1044 1000 +44
plugin/skills/azure-observability/SKILL.md 939 500 +439
plugin/skills/azure-postgres/SKILL.md 1519 500 +1019
plugin/skills/azure-postgres/references/entra-rbac-overview.md 1823 1000 +823
plugin/skills/azure-postgres/references/group-sync.md 1844 1000 +844
plugin/skills/azure-postgres/references/permission-templates.md 1647 1000 +647
plugin/skills/azure-postgres/references/troubleshooting.md 1959 1000 +959
plugin/skills/azure-prepare/SKILL.md 1545 500 +1045
plugin/skills/azure-prepare/references/aspire.md 2675 1000 +1675
plugin/skills/azure-prepare/references/azure-context.md 1019 1000 +19
plugin/skills/azure-prepare/references/recipes/azd/aspire.md 1584 1000 +584
plugin/skills/azure-prepare/references/recipes/azd/azure-yaml.md 1803 1000 +803
plugin/skills/azure-prepare/references/recipes/azd/terraform.md 2924 1000 +1924
plugin/skills/azure-prepare/references/research.md 1600 1000 +600
plugin/skills/azure-prepare/references/runtimes/nodejs.md 1508 1000 +508
plugin/skills/azure-prepare/references/security.md 1784 1000 +784
plugin/skills/azure-prepare/references/services/functions/bicep.md 1896 1000 +896
plugin/skills/azure-prepare/references/services/functions/templates/SPEC-composable-templates.md 6187 1000 +5187
plugin/skills/azure-prepare/references/services/functions/templates/recipes/README.md 1265 1000 +265
plugin/skills/azure-prepare/references/services/functions/templates/recipes/common/uami-bindings.md 1223 1000 +223
plugin/skills/azure-prepare/references/services/functions/templates/recipes/composition.md 3150 1000 +2150
plugin/skills/azure-prepare/references/services/functions/templates/recipes/cosmosdb/README.md 1467 1000 +467
plugin/skills/azure-prepare/references/services/functions/templates/recipes/durable/README.md 1149 1000 +149
plugin/skills/azure-prepare/references/services/functions/templates/recipes/eventhubs/README.md 1403 1000 +403
plugin/skills/azure-prepare/references/services/functions/templates/recipes/mcp/source/java.md 1312 1000 +312
plugin/skills/azure-prepare/references/services/functions/templates/recipes/mcp/source/python.md 1207 1000 +207
plugin/skills/azure-prepare/references/services/functions/templates/recipes/mcp/source/typescript.md 1075 1000 +75
plugin/skills/azure-prepare/references/services/functions/templates/recipes/servicebus/README.md 1171 1000 +171
plugin/skills/azure-prepare/references/services/functions/templates/recipes/servicebus/source/dotnet.md 1227 1000 +227
plugin/skills/azure-prepare/references/services/functions/templates/recipes/sql/source/java.md 1009 1000 +9
plugin/skills/azure-prepare/references/services/functions/templates/recipes/sql/source/python.md 1080 1000 +80
plugin/skills/azure-prepare/references/services/functions/terraform.md 2305 1000 +1305
plugin/skills/azure-prepare/references/services/service-bus/patterns.md 1010 1000 +10
plugin/skills/azure-resource-lookup/SKILL.md 1379 500 +879
plugin/skills/azure-resource-lookup/references/azure-resource-graph.md 1307 1000 +307
plugin/skills/azure-resource-visualizer/SKILL.md 2091 500 +1591
plugin/skills/azure-storage/SKILL.md 1092 500 +592
plugin/skills/azure-storage/references/sdk-usage.md 1096 1000 +96
plugin/skills/azure-validate/SKILL.md 734 500 +234
plugin/skills/entra-app-registration/SKILL.md 2055 500 +1555
plugin/skills/entra-app-registration/references/api-permissions.md 2545 1000 +1545
plugin/skills/entra-app-registration/references/cli-commands.md 2211 1000 +1211
plugin/skills/entra-app-registration/references/console-app-example.md 2752 1000 +1752
plugin/skills/entra-app-registration/references/first-app-registration.md 1846 1000 +846
plugin/skills/entra-app-registration/references/oauth-flows.md 2375 1000 +1375
plugin/skills/entra-app-registration/references/troubleshooting.md 1896 1000 +896
plugin/skills/microsoft-foundry/SKILL.md 1912 500 +1412
plugin/skills/microsoft-foundry/foundry-agent/create/agent-framework/SKILL.md 1671 500 +1171
plugin/skills/microsoft-foundry/foundry-agent/create/agent-framework/references/debug-setup.md 1689 1000 +689
plugin/skills/microsoft-foundry/foundry-agent/deploy/deploy.md 3295 1000 +2295
plugin/skills/microsoft-foundry/foundry-agent/invoke/invoke.md 1273 1000 +273
plugin/skills/microsoft-foundry/foundry-agent/troubleshoot/troubleshoot.md 1299 1000 +299
plugin/skills/microsoft-foundry/models/deploy-model/SKILL.md 1627 500 +1127
plugin/skills/microsoft-foundry/models/deploy-model/capacity/SKILL.md 1725 500 +1225
plugin/skills/microsoft-foundry/models/deploy-model/customize/SKILL.md 2220 500 +1720
plugin/skills/microsoft-foundry/models/deploy-model/customize/references/customize-workflow.md 1859 1000 +859
plugin/skills/microsoft-foundry/models/deploy-model/preset/SKILL.md 1212 500 +712
plugin/skills/microsoft-foundry/models/deploy-model/preset/references/preset-workflow.md 4252 1000 +3252
plugin/skills/microsoft-foundry/models/deploy-model/preset/references/workflow.md 1315 1000 +315
plugin/skills/microsoft-foundry/project/create/create-foundry-project.md 1218 1000 +218
plugin/skills/microsoft-foundry/quota/references/ptu-guide.md 1473 1000 +473
plugin/skills/microsoft-foundry/quota/references/troubleshooting.md 1807 1000 +807
plugin/skills/microsoft-foundry/quota/references/workflows.md 1614 1000 +614
plugin/skills/microsoft-foundry/rbac/rbac.md 1752 1000 +752
plugin/skills/microsoft-foundry/references/sdk/foundry-sdk-py.md 1888 1000 +888
plugin/skills/microsoft-foundry/resource/create/create-foundry-resource.md 1489 1000 +489
plugin/skills/microsoft-foundry/resource/create/references/workflows.md 1637 1000 +637
.github/agents/SkillCreator.agent.md 1044 1000 +44

Consider moving content to references/ subdirectories.


Automated token analysis. See skill authoring guidelines for best practices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

azure-prepare skill generates incorrect azure.yaml for .NET Aspire AppHost projects

3 participants