Skip to content

Fix VS Code AppHost launch path resolution#17408

Open
davidfowl wants to merge 11 commits into
mainfrom
codex/vscode-apphost-launch-path
Open

Fix VS Code AppHost launch path resolution#17408
davidfowl wants to merge 11 commits into
mainfrom
codex/vscode-apphost-launch-path

Conversation

@davidfowl
Copy link
Copy Markdown
Contributor

@davidfowl davidfowl commented May 23, 2026

Description

This fixes VS Code AppHost launch path handling when users run or debug Aspire from source files instead of project files. Previously, starting an Aspire debug session from an SDK-style C# AppHost source file such as Program.cs could pass that source path through to the Aspire CLI as --apphost <path>/Program.cs, which the CLI does not accept for SDK-style AppHosts.

The extension now uses CLI-backed AppHost discovery as the source of truth for launch targets:

  • aspire ls --format json discovers AppHost candidates for the workspace.
  • aspire ls also includes the AppHost configured in aspire.config.json, even when that AppHost lives outside the current working directory's normal discovery results.
  • SDK-style C# AppHost source files under a discovered .csproj resolve to that project file before launch.
  • Single-file C# AppHosts and TypeScript/JavaScript AppHosts continue to launch from their discovered source file paths.
  • Launch configurations are normalized after VS Code variable substitution, so ${workspaceFolder}/AppHost/Program.cs can resolve to the discovered AppHost project.
  • Debug configuration providers, editor Run/Debug contexts, and the AppHost tree share the same discovery service and refresh when AppHost-related files or config files change.
  • Discovery failures are handled defensively in editor and debug-provider paths so stale VS Code contexts or transient CLI discovery failures do not break Run/Debug flows.
  • Discovery CLI processes are tracked, cancelled on dispose, and timed out so hung discovery does not leave permanently cached pending promises.
  • File watcher invalidations ignore output and vendor directories before clearing discovery cache.

User-facing usage

Users can still point an Aspire launch configuration at the AppHost project file:

{
  "type": "aspire",
  "request": "launch",
  "program": "${workspaceFolder}/AppHost/AppHost.csproj"
}

If a user starts debugging while an SDK-style AppHost source file is active, or a launch configuration points at that source file, the extension resolves the launch target to the containing discovered AppHost project before invoking the CLI. Single-file AppHosts still launch directly from source:

#:sdk Aspire.AppHost.Sdk

var builder = DistributedApplication.CreateBuilder(args);
builder.Build().Run();

TypeScript AppHosts discovered by the CLI continue to launch from the source file path:

import { createBuilder } from './.aspire/modules/aspire';

Fixes # (issue)

Validation

  • npm run compile-tests -- --pretty false
  • npm run unit-test -- --grep "AspireDebugConfigurationProvider"
  • npm run unit-test -- --grep "TypeScript apphost|AspireEditorCommandProvider|AppHost discovery|AspireDebugConfigurationProvider"
  • dotnet test --project tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj --no-launch-profile -- --filter-class "*.LsCommandTests" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"
  • C# AppHost discovery: cd tests/testproject && aspire ls --format json
  • Local CLI configured AppHost discovery: temporary workspace with aspire.config.json pointing outside the working directory, then dotnet run --project src/Aspire.Cli/Aspire.Cli.csproj -- ls --format json verified the configured AppHost is included.
  • TypeScript AppHost discovery: created a temporary workspace with aspire init --language typescript --suppress-agent-init --non-interactive, then ran aspire ls --format json and verified it returns the apphost.ts candidate with language: "typescript/nodejs".
  • git diff --check

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 requested a review from adamint as a code owner May 23, 2026 05:22
Copilot AI review requested due to automatic review settings May 23, 2026 05:22
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 23, 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 -- 17408

Or

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

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

This PR fixes Aspire VS Code extension launch path handling so that when users start an Aspire debug session from an SDK-style C# AppHost source file (typically Program.cs), the extension resolves that source path to the containing AppHost project (.csproj) before invoking the Aspire CLI via --apphost.

Changes:

  • Added resolveAppHostLaunchPath utility to normalize C# AppHost launch paths (Program.cs → containing project; single-file #:sdk Aspire.AppHost.Sdk stays as source).
  • Updated AspireEditorCommandProvider.getAppHostPath() to return the normalized launch path when launching from the active editor.
  • Updated AspireDebugConfigurationProvider.resolveDebugConfigurationWithSubstitutedVariables() to normalize launch.json program values post-substitution, with unit tests covering key scenarios.
Show a summary per file
File Description
extension/src/utils/appHostLaunchPath.ts Introduces the path normalization logic for C# AppHost launches.
extension/src/editor/AspireEditorCommandProvider.ts Uses normalization when launching from the active editor’s AppHost file.
extension/src/debugger/AspireDebugConfigurationProvider.ts Normalizes program after variable substitution for launch configs.
extension/src/test/aspireEditorCommandProvider.test.ts Adds unit tests for active-editor launch path normalization.
extension/src/test/aspireDebugConfigurationProvider.test.ts Adds unit tests for launch configuration normalization behavior.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 1

Comment thread extension/src/utils/appHostLaunchPath.ts Outdated
@davidfowl
Copy link
Copy Markdown
Contributor Author

Replying to Copilot review overview #17408 (review): thanks for the review. The PR has since been refactored from the original resolveAppHostLaunchPath utility to shared CLI-backed AppHost discovery, so the stale overview no longer reflects the current file layout and no code change was needed for this summary.

davidfowl and others added 2 commits May 23, 2026 07:15
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Member

@JamesNK JamesNK left a comment

Choose a reason for hiding this comment

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

Reviewed the AppHost discovery refactor. Found 2 issues:\n\n- 1 resource leak/correctness issue: Spawned CLI process in runCliForStdout is never tracked — no timeout, no kill-on-dispose, and a hung process permanently blocks the cached discovery promise for the workspace.\n- 1 performance issue: File system watchers use broad **/*.csproj patterns without excluding build output directories, which can trigger excessive CLI re-invocations during builds in large workspaces.

Comment thread extension/src/utils/appHostDiscovery.ts Outdated
Comment thread extension/src/utils/appHostDiscovery.ts
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@davidfowl
Copy link
Copy Markdown
Contributor Author

Replying to review summary #17408 (review): thanks, agreed on both points. I addressed the inline threads in c3c8505 by adding discovery CLI timeout/cancellation on dispose and filtering watcher invalidations for output and vendor directories.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
davidfowl and others added 3 commits May 25, 2026 06:37
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

Re-running the failed jobs in the CI workflow for this pull request because 1 job was identified as retry-safe transient failures in the CI run attempt.
GitHub was asked to rerun all failed jobs for that attempt, and the rerun is being tracked in the rerun attempt.
The job links below point to the failed attempt jobs that matched the retry-safe transient failure rules.

@github-actions
Copy link
Copy Markdown
Contributor

CLI E2E Tests failed — 95 passed, 1 failed, 5 unknown (commit db92159)

Failed Tests

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
AgentMcpListStructuredLogsFromStarterAppCore ▶️ View recording
AllPublishMethodsBuildDockerImages ▶️ View recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View recording
AspireInitSingleFileAppHostRunsViaDotnetRunAppHost ▶️ View recording
AspireInitWithExistingAppHostDirRecreatesMissingNuGetConfigAndPreservesFiles ▶️ View recording
AspireInitWithSolutionFileGeneratesAppHostThatBuildsAgainstChannelHive ▶️ View recording
AspireStartUpdatesStaleTypeScriptAppHostPath ▶️ 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
DashboardRunWithAgentMcpCore ▶️ View recording
DashboardRunWithOtelTracesReturnsNoTracesCore ▶️ 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 failure recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View recording
GeneratedAspireDevScript_StartsWatchMode_WithConfiguredToolchain ▶️ 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
PublishJavaScriptPatternsGeneratesExpectedDockerComposeArtifacts ▶️ 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 #26405806207

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.

3 participants