Skip to content

Fix azd AppHost detection before restore - #22635

Open
Karol Zadora-Przylecki (karolz-ms) wants to merge 1 commit into
mainfrom
dev/karolz/dotnet-project-publishing
Open

Karol Zadora-Przylecki (karolz-ms) wants to merge 1 commit into
mainfrom
dev/karolz/dotnet-project-publishing

Conversation

@karolz-ms

Copy link
Copy Markdown
Contributor

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: c6493b9154d315e073a6261e631bb4adeadacb12

Dimension Assessment Rationale
Change confidence 7.5/10 ↑ All four source-generated templates satisfy the detection query before restore.
↑ Two existing AppHost SDK tests pass.
↓ The packaged-template regression test cannot initialize without the isolated test SDK; actual azd provisioning was not exercised.
Diagnosis confidence 9/10 ↑ Clean package-based AppHosts lack both detection indicators before restore, and azd falls back to default infrastructure when AppHost detection fails.
Evidence fit 4/10 ↑ The fallback targets the reported missing infra/main.bicep.
↓ The reporter's AppHost SDK, azd version, and pipeline restore order are unknown; the reported pipeline was not reproduced.

Description

Fix clean-checkout AppHost detection before NuGet restore so azd can generate Aspire infrastructure rather than falling back to a checked-in infra/main.bicep. This fixes a detection gap that may explain the failure in #22550; the reporter's specific project and pipeline still need confirmation.

The four C# AppHost templates now declare IsAspireHost explicitly. The migration guides explain the same requirement for existing projects, and a regression theory exercises azd's detection predicate on generated projects before restore. Resource publishing and AddDotnetProject behavior are unchanged.

Fixes #22550

User-facing usage

Existing AppHosts migrated to Microsoft.NET.Sdk can make their identity available before restore:

<PropertyGroup>
  <IsAspireHost>true</IsAspireHost>
</PropertyGroup>

Restoring the AppHost before starting azd is another workaround for this detection gap.

Validation

  • Generated all four templates from source without restoring and ran dotnet msbuild <apphost.csproj> --ignore:.sln -nologo --getProperty:IsAspireHost --getItem:ProjectCapability: passed after the change; the same query failed to detect all four before it.
  • dotnet build tests/Aspire.Templates.Tests/Aspire.Templates.Tests.csproj --no-restore --verbosity quiet: passed.
  • dotnet test --project tests/Aspire.Hosting.Sdk.Tests/Aspire.Hosting.Sdk.Tests.csproj --no-launch-profile -- --filter-method '*.PackagePropsDisableFileBasedAppHostAot' --filter-method '*.AppHostTargetsDefaultAspireHostingSDKVersionWhenSdkIsNotUsed' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true': passed, two tests.
  • dotnet test --project tests/Aspire.Templates.Tests/Aspire.Templates.Tests.csproj --no-launch-profile -- --filter-method '*.AppHostIsDetectableBeforeRestore' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true': blocked; all four cases fail during harness initialization because the isolated template-test SDK is not installed. The regression assertions did not run.
  • An actual azd provision and the reporter's pipeline were not run.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 22635

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 22635"

@github-actions

Copy link
Copy Markdown
Contributor

Tests selector

3 / 101 PR test projects · 3 PR jobs, from 5 changed files.

Selected PR test projects (3 / 101)

Aspire.Cli.EndToEnd.Tests, Aspire.Cli.Tests, Aspire.Templates.Tests

Selected PR jobs (3)

cli-starter-validation, homebrew-installer, winget-installer


How these were chosen — grouped by what changed

🔧 src/Aspire.ProjectTemplates/templates/aspire-apphost/Aspire.AppHost1.csproj (changed source)
→ 3 directly: Aspire.Cli.EndToEnd.Tests, Aspire.Cli.Tests, Aspire.Templates.Tests

🔧 src/Aspire.ProjectTemplates/templates/aspire-empty/AspireApplication.1.AppHost/AspireApplication.1.AppHost.csproj (changed source)
→ 3 directly: Aspire.Cli.EndToEnd.Tests, Aspire.Cli.Tests, Aspire.Templates.Tests

🔧 src/Aspire.ProjectTemplates/templates/aspire-starter/Aspire-StarterApplication.1.AppHost/Aspire-StarterApplication.1.AppHost.csproj (changed source)
→ 3 directly: Aspire.Cli.EndToEnd.Tests, Aspire.Cli.Tests, Aspire.Templates.Tests

🔧 src/Aspire.ProjectTemplates/templates/aspire-ts-cs-starter/Aspire-StarterApplication.1.AppHost/Aspire-StarterApplication.1.AppHost.csproj (changed source)
→ 3 directly: Aspire.Cli.EndToEnd.Tests, Aspire.Cli.Tests, Aspire.Templates.Tests

🧪 tests/Aspire.Templates.Tests/AppHostTemplateTests.cs (changed test)
→ 1 directly: Aspire.Templates.Tests

Job reasons

Job Triggered by
cli-starter-validation src/Aspire.ProjectTemplates/templates/aspire-starter/Aspire-StarterApplication.1.AppHost/Aspire-StarterApplication.1.AppHost.csproj
homebrew-installer src/Aspire.ProjectTemplates/templates/aspire-apphost/Aspire.AppHost1.csproj, src/Aspire.ProjectTemplates/templates/aspire-empty/AspireApplication.1.AppHost/AspireApplication.1.AppHost.csproj, src/Aspire.ProjectTemplates/templates/aspire-starter/Aspire-StarterApplication.1.AppHost/Aspire-StarterApplication.1.AppHost.csproj, src/Aspire.ProjectTemplates/templates/aspire-ts-cs-starter/Aspire-StarterApplication.1.AppHost/Aspire-StarterApplication.1.AppHost.csproj
winget-installer src/Aspire.ProjectTemplates/templates/aspire-apphost/Aspire.AppHost1.csproj, src/Aspire.ProjectTemplates/templates/aspire-empty/AspireApplication.1.AppHost/AspireApplication.1.AppHost.csproj, src/Aspire.ProjectTemplates/templates/aspire-starter/Aspire-StarterApplication.1.AppHost/Aspire-StarterApplication.1.AppHost.csproj, src/Aspire.ProjectTemplates/templates/aspire-ts-cs-starter/Aspire-StarterApplication.1.AppHost/Aspire-StarterApplication.1.AppHost.csproj

Selection computed for commit c6493b9.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The packaged-template regression assertions have not run, and the reported pipeline failure remains unreproduced, requiring CI and human validation to confirm the fix addresses #22550.

No open issues 🎉

What changed in this PR

This PR makes generated C# AppHosts recognizable by azd before NuGet restore, addressing a detection gap that may explain #22550. Resource publishing and AddDotnetProject behavior remain unchanged.

Changes:

  • Declare IsAspireHost explicitly in all four C# AppHost templates.
  • Add a regression theory checking pre-restore detection for each template.
  • Document the identity requirement for existing projects migrating away from the AppHost SDK.
File Description
tests/​Aspire.Templates.Tests/​AppHostTemplateTests.cs Adds pre-restore detection coverage for all four templates.
src/​Aspire.ProjectTemplates/​templates/​aspire-ts-cs-starter/​Aspire-StarterApplication.1.AppHost/​Aspire-StarterApplication.1.AppHost.csproj Declares AppHost identity in the TypeScript/C# starter.
src/​Aspire.ProjectTemplates/​templates/​aspire-starter/​Aspire-StarterApplication.1.AppHost/​Aspire-StarterApplication.1.AppHost.csproj Declares AppHost identity in the C# starter.
src/​Aspire.ProjectTemplates/​templates/​aspire-empty/​AspireApplication.1.AppHost/​AspireApplication.1.AppHost.csproj Declares AppHost identity in the empty solution template.
src/​Aspire.ProjectTemplates/​templates/​aspire-apphost/​Aspire.AppHost1.csproj Declares AppHost identity in the standalone template.
docs/​migrate-from-apphost-sdk.md Explains explicit identity and the restore workaround.
docs/​migrate-from-addproject.md Distinguishes project identity from resource-registration migration.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The migration guide’s restore workaround needs to be scoped to .csproj AppHosts because azd still cannot detect file-based AppHosts after the SDK directive is replaced, even after restore.

1 open issue

Review effort: Max

NuGet imports have been generated. Declaring the property explicitly preserves detection
on clean CI agents. Otherwise, `azd provision` can treat the project as an ordinary .NET
service and look for a checked-in `infra/main.bicep` instead of generating infrastructure.
Restoring the AppHost before starting `azd` is a workaround for this detection gap.
@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AddDotnetProject fails with azd provision (DevOps Pipelines)

2 participants