Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Aspire.Cli/Commands/AppHostLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ internal static void AddLaunchOptions(Command command)
/// <param name="format">The output format (JSON or table).</param>
/// <param name="isolated">Whether to run in isolated mode.</param>
/// <param name="isExtensionHost">Whether running inside VS Code extension.</param>
/// <param name="waitForDebugger">Whether the AppHost is waiting for a debugger to attach.</param>
/// <param name="globalArgs">Global CLI args to forward to child process.</param>
/// <param name="additionalArgs">Additional unmatched args to forward.</param>
/// <param name="cancellationToken">Cancellation token.</param>
Expand All @@ -79,6 +80,7 @@ public async Task<int> LaunchDetachedAsync(
OutputFormat? format,
bool isolated,
bool isExtensionHost,
bool waitForDebugger,
IEnumerable<string> globalArgs,
IEnumerable<string> additionalArgs,
CancellationToken cancellationToken)
Expand Down Expand Up @@ -119,6 +121,16 @@ public async Task<int> LaunchDetachedAsync(

logger.LogDebug("Waiting for socket with prefix: {SocketPrefix}, Hash: {Hash}", expectedSocketPrefix, expectedHash);

// If --wait-for-debugger is active, show a message so the user knows the AppHost
// is paused. In detached mode we don't have the AppHost PID (stdout is suppressed),
// so we show a generic message without a PID.
if (waitForDebugger)
{
interactionService.DisplayMessage(
KnownEmojis.Bug,
InteractionServiceStrings.WaitingForDebuggerToAttachToAppHost);
}

// Start the child process and wait for the backchannel
var launchResult = await interactionService.ShowStatusAsync(
RunCommandStrings.StartingAppHostInBackground,
Expand Down
13 changes: 11 additions & 2 deletions src/Aspire.Cli/Commands/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ protected override async Task<int> ExecuteAsync(ParseResult parseResult, Cancell
// The completion sources are the contract between RunCommand and IAppHostProject
var buildCompletionSource = new TaskCompletionSource<bool>();
var backchannelCompletionSource = new TaskCompletionSource<IAppHostCliBackchannel>();
var waitForDebugger = parseResult.GetValue(RootCommand.WaitForDebuggerOption);

context = new AppHostProjectContext
{
Expand All @@ -224,14 +225,14 @@ protected override async Task<int> ExecuteAsync(ParseResult parseResult, Cancell
Debug = parseResult.GetValue(RootCommand.DebugOption),
NoBuild = noBuild,
NoRestore = noBuild, // --no-build implies --no-restore
WaitForDebugger = parseResult.GetValue(RootCommand.WaitForDebuggerOption),
WaitForDebugger = waitForDebugger,
Isolated = isolated,
StartDebugSession = startDebugSession,
EnvironmentVariables = new Dictionary<string, string>(),
UnmatchedTokens = parseResult.UnmatchedTokens.ToArray(),
WorkingDirectory = ExecutionContext.WorkingDirectory,
BuildCompletionSource = buildCompletionSource,
BackchannelCompletionSource = backchannelCompletionSource
BackchannelCompletionSource = backchannelCompletionSource,
};

// Start the project run as a pending task - we'll handle UX while it runs
Expand All @@ -250,6 +251,12 @@ protected override async Task<int> ExecuteAsync(ParseResult parseResult, Cancell
return await pendingRun;
}

// If --wait-for-debugger, display a message so the user knows the AppHost is paused.
if (waitForDebugger)
{
InteractionService.DisplayMessage(KnownEmojis.Bug, InteractionServiceStrings.WaitingForDebuggerToAttachToAppHost);
}

// Now wait for the backchannel to be established
var backchannel = await InteractionService.ShowStatusAsync(
isExtensionHost ? InteractionServiceStrings.BuildingAppHost : RunCommandStrings.ConnectingToAppHost,
Expand Down Expand Up @@ -619,6 +626,7 @@ private Task<int> ExecuteDetachedAsync(ParseResult parseResult, FileInfo? passed
var format = parseResult.GetValue(AppHostLauncher.s_formatOption);
var isolated = parseResult.GetValue(AppHostLauncher.s_isolatedOption);
var noBuild = parseResult.GetValue(s_noBuildOption);
var waitForDebugger = parseResult.GetValue(RootCommand.WaitForDebuggerOption);
var globalArgs = RootCommand.GetChildProcessArgs(parseResult);
var additionalArgs = parseResult.UnmatchedTokens.Where(t => t != "--detach").ToList();

Expand All @@ -632,6 +640,7 @@ private Task<int> ExecuteDetachedAsync(ParseResult parseResult, FileInfo? passed
format,
isolated,
isExtensionHost,
waitForDebugger,
globalArgs,
additionalArgs,
cancellationToken);
Expand Down
2 changes: 2 additions & 0 deletions src/Aspire.Cli/Commands/StartCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected override async Task<int> ExecuteAsync(ParseResult parseResult, Cancell

var noBuild = parseResult.GetValue(s_noBuildOption);
var isExtensionHost = ExtensionHelper.IsExtensionHost(_interactionService, out _, out _);
var waitForDebugger = parseResult.GetValue(RootCommand.WaitForDebuggerOption);
var globalArgs = RootCommand.GetChildProcessArgs(parseResult);
var additionalArgs = parseResult.UnmatchedTokens.ToList();

Expand All @@ -62,6 +63,7 @@ protected override async Task<int> ExecuteAsync(ParseResult parseResult, Cancell
format,
isolated,
isExtensionHost,
waitForDebugger,
globalArgs,
additionalArgs,
cancellationToken);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/Aspire.Hosting/DistributedApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,15 @@ private static void WaitForDebugger()
if (Environment.GetEnvironmentVariable(KnownConfigNames.WaitForDebugger) == "true")
{
var startedWaiting = DateTimeOffset.UtcNow;
TimeSpan timeout = TimeSpan.FromSeconds(30);
var timeout = TimeSpan.FromSeconds(30);

if (Environment.GetEnvironmentVariable(KnownConfigNames.WaitForDebuggerTimeout) is string timeoutString && int.TryParse(timeoutString, out var timeoutSeconds))
{
timeout = TimeSpan.FromSeconds(timeoutSeconds);
}

Console.WriteLine($"AppHost PID: {Environment.ProcessId}");

while (Debugger.IsAttached == false)
{
Console.WriteLine($"Waiting for debugger to attach to process: {Environment.ProcessId}");
Expand Down
Loading