Skip to content

Optimize no-build AppHost project inspection#17246

Merged
davidfowl merged 1 commit into
mainfrom
davidfowl/optimize-apphost-msbuild-cache
May 20, 2026
Merged

Optimize no-build AppHost project inspection#17246
davidfowl merged 1 commit into
mainfrom
davidfowl/optimize-apphost-msbuild-cache

Conversation

@davidfowl
Copy link
Copy Markdown
Contributor

@davidfowl davidfowl commented May 19, 2026

Description

aspire run --no-build for .NET AppHost projects was spending startup time re-evaluating the same AppHost MSBuild metadata multiple times before launching the AppHost. This change centralizes AppHost metadata resolution so each CLI process evaluates the project once, and then persists successful inspection results in a project-input disk cache for subsequent CLI runs.

The resolver now owns the single source of truth for AppHost project metadata used by validation, compatibility checks, CLI bundle handoff, and isolated user-secrets cloning. The disk cache is keyed by the project path plus filesystem inputs that affect the evaluated MSBuild result, including the project file, restore assets file, conventional Directory.Build/Directory.Packages imports, global.json, and an explicit cache schema version. Writes use a random temp file plus atomic replace, and the resolver re-checks the cache key before publishing a result so a project edit during MSBuild evaluation cannot write stale metadata under a new key.

aspire cache clear removes the AppHost info cache. Users can disable the disk cache with the normal Aspire config command:

aspire config set dotnetAppHostInfoCacheDisabled true

The toggle is read through Aspire config files/global config rather than environment variables. Disabling the disk cache still keeps the per-process in-memory coalescing, so a single CLI invocation does not regress to the original repeated MSBuild inspections.

Validation

  • dotnet build tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj /p:SkipNativeBuild=true --no-restore
  • dotnet test --project tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj --no-build --no-launch-profile -- --filter-class "*.AppHostInfoResolverTests" --filter-class "*.AppHostInfoDiskCacheTests" --filter-class "*.CacheCommandTests" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"
  • dotnet test --project tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj --no-launch-profile -- --filter-class "*.AppHostInfoDiskCacheTests" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"
  • Startup profile captures with update notifications disabled:
Scenario Wall CLI command minus 8s capture delay find_apphost AppHost inspection MSBuild
Cache disabled 17.6s 5.81s 701.7ms 1 x 618.6ms
Cold disk cache 16.1s 4.79s 695.4ms 1 x 658.6ms
Warm disk cache 15.1s 3.81s 23.7ms 0

Fixes #17197

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

@davidfowl davidfowl changed the base branch from davidfowl/aspire-managed-tracing to main May 19, 2026 06:29
@davidfowl davidfowl force-pushed the davidfowl/optimize-apphost-msbuild-cache branch from 7304864 to 3559234 Compare May 19, 2026 06:36
Copilot AI review requested due to automatic review settings May 19, 2026 06:36
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 19, 2026

🚀 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 -- 17246

Or

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Centralizes .NET AppHost MSBuild inspection in the Aspire CLI to avoid repeated project evaluations (especially on aspire run/start --no-build), and adds a content-keyed disk cache so subsequent CLI runs can reuse prior inspection results when inputs haven’t changed.

Changes:

  • Introduces an AppHostInfoResolver that coalesces MSBuild inspection in-memory (per CLI process) and optionally persists successful results to disk.
  • Adds an AppHost-info disk cache keyed by project path + relevant filesystem inputs, and wires it into CLI DI and cache clear.
  • Updates CLI tests and test fakes to reflect the new single-probe inspection shape, and adds targeted coverage for resolver + disk cache behavior.
Show a summary per file
File Description
tests/Aspire.Cli.Tests/Utils/CliTestHelper.cs Registers the resolver + a no-op disk cache for tests.
tests/Aspire.Cli.Tests/TestServices/TestDotNetCliRunner.cs Extends the test runner to support async MSBuild probe callbacks and legacy-compat JSON synthesis.
tests/Aspire.Cli.Tests/TestServices/NullDiskCache.cs Adds a no-op IAppHostInfoDiskCache implementation for tests.
tests/Aspire.Cli.Tests/Projects/DotNetAppHostProjectTests.cs Adjusts expected MSBuild JSON shape to include AppHost detection properties.
tests/Aspire.Cli.Tests/Projects/AppHostInfoResolverTests.cs New tests validating disk-cache hits, in-memory caching, concurrency coalescing, and cancellation semantics.
tests/Aspire.Cli.Tests/Commands/RunCommandTests.cs Updates isolated user-secrets test to match the consolidated MSBuild response shape.
tests/Aspire.Cli.Tests/Commands/CacheCommandTests.cs Adds coverage ensuring aspire cache clear removes the apphost-info cache directory.
tests/Aspire.Cli.Tests/Caching/AppHostInfoDiskCacheTests.cs New tests for cache key stability/invalidation, disabled mode, and concurrent writes.
src/Aspire.Cli/Utils/AppHostHelper.cs Extracts EvaluateAppHostCompatibility to allow compatibility gating without re-running MSBuild.
src/Aspire.Cli/Projects/DotNetAppHostProject.cs Routes validation/compatibility/bundle/user-secrets probing through the shared resolver to avoid repeated MSBuild evaluations.
src/Aspire.Cli/Projects/AppHostInfoResolver.cs New resolver implementing in-memory coalescing + disk-cache integration for AppHost project inspection.
src/Aspire.Cli/Program.cs Registers the disk cache + resolver in CLI DI.
src/Aspire.Cli/JsonSourceGenerationContext.cs Adds source-gen serialization metadata for the new cache/inspection payload types.
src/Aspire.Cli/Caching/AppHostInfoDiskCache.cs New content-keyed disk cache implementation for AppHost inspection results.

Copilot's findings

  • Files reviewed: 14/14 changed files
  • Comments generated: 4

Comment thread src/Aspire.Cli/Caching/AppHostInfoDiskCache.cs Outdated
Comment thread src/Aspire.Cli/Caching/AppHostInfoDiskCache.cs Outdated
Comment thread src/Aspire.Cli/Caching/AppHostInfoDiskCache.cs
Comment thread src/Aspire.Cli/Utils/AppHostHelper.cs Outdated
@davidfowl
Copy link
Copy Markdown
Contributor Author

Replying to the Copilot review overview: thanks for the overview. This is an automated summary of the PR with no actionable feedback, so no changes are required here.

Comment thread src/Aspire.Cli/Projects/AppHostInfoResolver.cs
Comment thread src/Aspire.Cli/Utils/AppHostHelper.cs Outdated
Centralize .NET AppHost MSBuild metadata inspection, coalesce per-process probes, and add a content-keyed disk cache so warm no-build startup can skip repeated project evaluations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@davidfowl davidfowl force-pushed the davidfowl/optimize-apphost-msbuild-cache branch from 9644659 to 0fea635 Compare May 20, 2026 14:51
@github-actions
Copy link
Copy Markdown
Contributor

CLI E2E Tests unknown — 94 passed, 0 failed, 2 unknown (commit 0fea635)

View all recordings
Status Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View recording
AddPackageWhileAppHostRunningDetached ▶️ View recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View recording
AgentInitCommand_DefaultSelection_InstallsDefaultSkills ▶️ View recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View recording
AllPublishMethodsBuildDockerImages ▶️ View recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View recording
AspireInitSingleFileAppHostRunsViaDotnetRunAppHost ▶️ View recording
AspireInitWithExistingAppHostDirRecreatesMissingNuGetConfigAndPreservesFiles ▶️ View recording
AspireInitWithSolutionFileGeneratesAppHostThatBuildsAgainstChannelHive ▶️ View recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View recording
AspireUpdateRemovesOrphanAppHostPackageVersionWhenSdkAlreadyCurrent ▶️ View recording
Banner_DisplayedOnFirstRun ▶️ View recording
Banner_DisplayedWithExplicitFlag ▶️ View recording
Banner_NotDisplayedWithNoLogoFlag ▶️ View recording
CertificatesClean_RemovesCertificates ▶️ View recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View recording
CreateAndRunAspireStarterProject ▶️ View recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View recording
CreateAndRunEmptyAppHostProject ▶️ View recording
CreateAndRunJavaEmptyAppHostProject ▶️ View recording
CreateAndRunJsReactProject ▶️ View recording
CreateAndRunPythonReactProject ▶️ View recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View recording
CreateAndRunTypeScriptStarterProject ▶️ View recording
CreateJavaAppHostWithViteApp ▶️ View recording
CreateTypeScriptAppHostWithViteApp_UsesConfiguredToolchain ▶️ View recording
DashboardRunWithOtelTracesReturnsNoTraces ▶️ View recording
DeployK8sBasicApiService ▶️ View recording
DeployK8sWithExternalHelmChart ▶️ View recording
DeployK8sWithGarnet ▶️ View recording
DeployK8sWithMongoDB ▶️ View recording
DeployK8sWithMySql ▶️ View recording
DeployK8sWithPostgres ▶️ View recording
DeployK8sWithRabbitMQ ▶️ View recording
DeployK8sWithRedis ▶️ View recording
DeployK8sWithSqlServer ▶️ View recording
DeployK8sWithValkey ▶️ View recording
DeployTypeScriptAppToKubernetes ▶️ View recording
DescribeCommandResolvesReplicaNames ▶️ View recording
DescribeCommandShowsRunningResources ▶️ View recording
DetachFormatJsonProducesValidJson ▶️ View recording
DetachFormatJsonProducesValidJsonWhenRestartingExistingInstance ▶️ View recording
DoListStepsShowsPipelineSteps ▶️ View recording
DocsCommand_RendersInteractiveMarkdownFromLocalSource ▶️ View recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View recording
DoctorCommand_TypeScriptAppHostReportsMissingConfiguredToolchain ▶️ View recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View recording
GlobalMigration_PreservesAllValueTypes ▶️ View recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View recording
InitTypeScriptAppHost_AugmentsExistingViteRepoAtRoot ▶️ View recording
InteractiveCSharpInitCreatesExpectedFiles ▶️ View recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View recording
JavaScriptHostingApisRunFromTypeScriptAppHost ▶️ View recording
LatestCliCanStartStableChannelAppHost ▶️ View recording
LatestCliCanStartStableChannelTypeScriptAppHost ▶️ View recording
LegacySettingsMigration_AdjustsRelativeAppHostPath ▶️ View recording
LogLevelTrace_ProducesTraceEntriesInCliLogFile ▶️ View recording
LogsCommandShowsResourceLogs ▶️ View recording
OtelLogsReturnsStructuredLogsFromStarterApp ▶️ View recording
OtelLogsReturnsStructuredLogsFromStarterAppIsolated ▶️ View recording
PsCommandListsRunningAppHost ▶️ View recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View recording
PublishWithConfigureEnvFileUpdatesEnvOutput ▶️ View recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View recording
PublishWithoutOutputPathUsesAppHostDirectoryDefault ▶️ View recording
ResourceCommand_FailedExecution_DisplaysAppHostLogPathAndLogContainsEntries ▶️ View recording
ResourceCommand_FailsWhenInteractionServiceIsRequired ▶️ View recording
ResourceCommand_SetAndDeleteParameterUpdatesDescribeOutput ▶️ View recording
RestoreGeneratesSdkFiles ▶️ View recording
RestoreGeneratesSdkFiles_WithConfiguredToolchain ▶️ View recording
RestoreRefreshesGeneratedSdkAfterAddingIntegration ▶️ View recording
RestoreSupportsConfigOnlyHelperPackageAndCrossPackageTypes ▶️ View recording
RunFromParentDirectory_UsesExistingConfigNearAppHost ▶️ View recording
RunPublishFailureScenarioAsync ▶️ View recording
RunReportsSyntaxErrorsForDotNetAppHost ▶️ View recording
RunReportsSyntaxErrorsForTypeScriptAppHost ▶️ View recording
SecretCrudOnDotNetAppHost ▶️ View recording
SecretCrudOnTypeScriptAppHost ▶️ View recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View recording
StartAndWaitForTypeScriptSqlServerAppHostWithNativeAssets ▶️ View recording
StartReportsSyntaxErrorsForDotNetAppHost ▶️ View recording
StartReportsSyntaxErrorsForTypeScriptAppHost ▶️ View recording
StopAllAppHostsFromAppHostDirectory ▶️ View recording
StopJavaPolyglotAppHostUsingApphostDirectory ▶️ View recording
StopNonInteractiveSingleAppHost ▶️ View recording
StopTypeScriptPolyglotAppHostUsingApphostDirectory ▶️ View recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View recording
UnAwaitedChainsCompileWithAutoResolvePromises ▶️ View recording
UpdateProjectChannelToStable_TypeScript_PicksUpStablePackages ▶️ View recording

📹 Recordings uploaded automatically from CI run #26170528351

@davidfowl davidfowl merged commit 521a617 into main May 20, 2026
303 checks passed
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 13.4 milestone May 20, 2026
@aspire-repo-bot
Copy link
Copy Markdown
Contributor

⚠️ Documentation drafting was attempted but the draft PR could not be confirmed.

See the workflow run for details: https://github.com/microsoft/aspire/actions/runs/26179694062

Drafted documentation updates for the AppHost info disk cache feature introduced in this PR. Three files were updated:

  • src/frontend/src/content/docs/reference/cli/includes/config-settings-table.md — Added dotnetAppHostInfoCacheDisabled config key entry.
  • src/frontend/src/content/docs/reference/cli/commands/aspire-cache-clear.mdx — Added AppHost project metadata to the list of what gets cleared.
  • src/frontend/src/content/docs/reference/cli/commands/aspire-run.mdx — Expanded --no-build description to explain the disk-caching behavior and how to manage it (aspire cache clear and dotnetAppHostInfoCacheDisabled).

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.

Improve no-build startup time for .NET AppHost projects

3 participants