Repository navigation
[C#DK v2 Aspire integration] Expose apphost query API and aspire resource management API from aspire extension #17705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Adam Ratzman (adamint)
merged 26 commits into
microsoft:main
from
LittleLittleCloud:u/xiaoyun/aspireC#DK
Jun 19, 2026
Merged
Changes from 11 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
2704831
Implement public API for Aspire extension and add fetchAppHostsOnce m…
LittleLittleCloud 91dc92d
Merge remote-tracking branch 'upstream/main' into pr-17705-csdk
adamint a030a21
Add Aspire test run DCP leases
adamint 33dcde3
Clean lease notifications after release
adamint 0e68f5b
Address Aspire extension API review feedback
adamint 8d8861b
Harden Aspire test run lease integration
adamint 12f2768
Refactor Aspire API to use DCP server for test run session management
LittleLittleCloud 45487b5
Merge branch 'main' into u/xiaoyun/aspireC#DK
LittleLittleCloud 2129f65
Refactor AspireDcpServer constructor to remove unused app parameter a…
LittleLittleCloud fdbba30
Update API function signatures to use inline arrow functions for DCP …
LittleLittleCloud c8739a3
Merge branch 'main' into u/xiaoyun/aspireC#DK
LittleLittleCloud b918206
Fix extension test failures by returning full E2E API from activate
LittleLittleCloud 5ca3d02
Refactor Aspire extension API: consolidate resource command functions…
LittleLittleCloud b9a3118
Fix stopRunSession cleanup and remove redundant closeLeaseNotificatio…
LittleLittleCloud d6666bc
Merge branch 'main' into u/xiaoyun/aspireC#DK
LittleLittleCloud 1321ec5
Enhance resource command handling and error logging in DCP server and…
LittleLittleCloud 9939510
Remove terminalProvider parameter from createExtensionApi function ca…
LittleLittleCloud 9fb1d95
Refactor process termination logic in AppHostDataRepository for clarity
LittleLittleCloud 79b9dbe
Refactor DCP server and test run session manager for improved session…
LittleLittleCloud bbdefca
Refactor AspireDcpServer and TestRunSessionManager for improved clari…
LittleLittleCloud 4d1ce6e
Fix test run session DCP credentials
adamint 03f2ff5
Merge remote-tracking branch 'upstream/main' into copilot/pr-17705-fix
adamint 8dbae32
Fix VS Code extension API lifecycle issues
adamint 0131c76
Handle selected test comment permission failures
adamint 778aea1
Merge upstream/main into PR 17705 fixes
adamint 08fabc5
Grant issue comment permission to CI tests workflow
adamint File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| import * as path from 'path'; | ||
| import { AppHostDataRepository, ResourceJson } from './views/AppHostDataRepository'; | ||
| import { AspireTerminalProvider } from './utils/AspireTerminalProvider'; | ||
| import { spawnCliProcess } from './debugger/languages/cli'; | ||
| import { AcquiredTestRunSession, TestRunSessionAcquireOptions } from './dcp/TestRunSessionManager'; | ||
| import AspireDcpServer from './dcp/AspireDcpServer'; | ||
|
|
||
| /** | ||
| * Public API exported by the Aspire extension for consumption by other extensions (e.g. C# Dev Kit). | ||
| */ | ||
| export interface AspireExtensionApi { | ||
| /** | ||
| * Fetches all currently running AppHosts with their resources. | ||
| * Performs a fresh CLI call independent of panel/polling state. | ||
| */ | ||
| getRunningAppHosts(): Promise<AppHostInfo[]> | ||
|
|
||
| /** | ||
| * Stops a running resource by name. | ||
| * Resolves when the CLI command completes. | ||
| */ | ||
| stopResource(resourceName: string, appHostPath: string): Promise<void> | ||
|
|
||
| /** | ||
| * Starts a stopped resource by name. | ||
| * Resolves when the CLI command completes. | ||
| */ | ||
| startResource(resourceName: string, appHostPath: string): Promise<void> | ||
|
|
||
| /** | ||
| * Acquires DCP connection environment for a test process that starts an AppHost in-process. | ||
| */ | ||
| acquireTestRunSession(options: TestRunSessionAcquireOptions): AcquiredTestRunSession | ||
|
|
||
| /** | ||
| * Releases a test-run DCP lease and stops resources started through it. | ||
| */ | ||
| releaseTestRunSession(id: string): Promise<void> | ||
| } | ||
|
|
||
| export interface AppHostInfo { | ||
| /** Absolute path to the AppHost project or source file. */ | ||
| appHostPath: string | ||
| /** Process ID of the running AppHost. */ | ||
| pid: number | ||
| /** Dashboard URL, if available. */ | ||
| dashboardUrl: string | null | ||
| /** Resources managed by this AppHost. */ | ||
| resources: ResourceInfo[] | ||
| } | ||
|
|
||
| export interface ResourceInfo { | ||
| /** Internal resource name as defined in the AppHost. */ | ||
| name: string | ||
| /** Display name for the resource. */ | ||
| displayName: string | null | ||
| /** Resource type (e.g. "Project", "Container"). */ | ||
| resourceType: string | ||
| /** Current state (e.g. "Running", "Stopped", "Building"). */ | ||
| state: string | null | ||
| /** Project path (.csproj) if this is a project resource, extracted from properties["project.path"]. */ | ||
| projectPath: string | null | ||
| /** Endpoint URLs exposed by the resource. */ | ||
| endpoints: { name: string | null; url: string }[] | ||
| /** Absolute path to the AppHost that owns this resource. */ | ||
| appHostPath: string | ||
| } | ||
|
|
||
| /** | ||
| * Creates the public API object backed by the given data repository. | ||
| */ | ||
| export function createAspireExtensionApi(dataRepository: AppHostDataRepository, terminalProvider: AspireTerminalProvider, dcpServer: { | ||
| acquireTestRunSession: (options: TestRunSessionAcquireOptions) => AcquiredTestRunSession, | ||
| releaseTestRunSession: (id: string) => Promise<void> | ||
| }): AspireExtensionApi { | ||
| return { | ||
| async getRunningAppHosts(): Promise<AppHostInfo[]> { | ||
| const appHosts = await dataRepository.fetchAppHostsOnce(); | ||
| return appHosts.map(appHost => ({ | ||
| appHostPath: appHost.appHostPath, | ||
| pid: appHost.appHostPid, | ||
| dashboardUrl: appHost.dashboardUrl, | ||
| resources: (appHost.resources ?? []).map(r => mapResource(r, appHost.appHostPath)), | ||
| })); | ||
| }, | ||
|
|
||
| async stopResource(resourceName: string, appHostPath: string): Promise<void> { | ||
| return executeResourceCommand(terminalProvider, resourceName, appHostPath, 'stop'); | ||
| }, | ||
|
|
||
| async startResource(resourceName: string, appHostPath: string): Promise<void> { | ||
| return executeResourceCommand(terminalProvider, resourceName, appHostPath, 'start'); | ||
| }, | ||
|
|
||
| acquireTestRunSession: (options) => dcpServer.acquireTestRunSession(options), | ||
| releaseTestRunSession: (id) => dcpServer.releaseTestRunSession(id), | ||
| }; | ||
| } | ||
|
|
||
| function mapResource(resource: ResourceJson, appHostPath: string): ResourceInfo { | ||
| return { | ||
| name: resource.name, | ||
| displayName: resource.displayName, | ||
| resourceType: resource.resourceType, | ||
| state: resource.state, | ||
| projectPath: resource.properties?.['project.path'] ?? null, | ||
| endpoints: (resource.urls ?? []) | ||
| .filter(u => !u.isInternal) | ||
| .map(u => ({ name: u.name, url: u.url })), | ||
| appHostPath, | ||
| }; | ||
| } | ||
|
|
||
| async function executeResourceCommand(terminalProvider: AspireTerminalProvider, resourceName: string, appHostPath: string, commandName: 'start' | 'stop'): Promise<void> { | ||
| const trimmedAppHostPath = appHostPath.trim(); | ||
| if (!trimmedAppHostPath || !path.isAbsolute(trimmedAppHostPath)) { | ||
| throw new Error('appHostPath must be a non-empty absolute path'); | ||
| } | ||
|
|
||
| const cliPath = await terminalProvider.getAspireCliExecutablePath(); | ||
| const args = ['resource', resourceName, commandName, '--apphost', trimmedAppHostPath]; | ||
| return new Promise<void>((resolve, reject) => { | ||
| let stdout = ''; | ||
| let stderr = ''; | ||
| let settled = false; | ||
|
|
||
| spawnCliProcess(terminalProvider, cliPath, args, { | ||
|
LittleLittleCloud marked this conversation as resolved.
Resolved
|
||
| noExtensionVariables: true, | ||
| stdoutCallback: (data) => { stdout += data; }, | ||
| stderrCallback: (data) => { stderr += data; }, | ||
| exitCallback: (code) => { | ||
| if (settled) { | ||
| return; | ||
| } | ||
|
|
||
| settled = true; | ||
| if (code === 0) { | ||
| resolve(); | ||
| } else { | ||
| const output = (stderr || stdout).trim(); | ||
| reject(new Error(`aspire resource ${commandName} exited with code ${code}${output ? `: ${output}` : ''}`)); | ||
| } | ||
| }, | ||
| errorCallback: (error) => { | ||
| if (settled) { | ||
| return; | ||
| } | ||
|
|
||
| settled = true; | ||
| reject(error); | ||
| }, | ||
| }); | ||
| }); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.