-
-
Notifications
You must be signed in to change notification settings - Fork 4
Only default to attaching debugger if aspire itself is under debug #31
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
Conversation
This allows for the common case that when running under debug, things should debug. However, if things are not under debug, probably don't need to attach the debugger. However, if a user wants to force it to, they can still call the .WithDebugger() method manually.
|
I think this check could be rolled into Lines 12 to 20 in 71717d4
Also, it should not actually attach the debugger if it can't find the instance of visual studio running attached to the aspire host project. C3D.Extensions.Aspire/src/C3D/Extensions/Aspire/VisualStudioDebug/AttachDebuggerHook.cs Lines 159 to 165 in 71717d4
But it does largely make sense to not add the annotation if the debugger is not attached when setting up the resource. public static bool IsDebugMode<TResource>(this IResourceBuilder<TResource> resourceBuilder, params string[]? environments)
where TResource : IResource =>
(resourceBuilder as IDebugBuilder<TResource>)?.IsDebugMode ?? (
System.Diagnostics.Debugger.IsAttached &&
resourceBuilder.ApplicationBuilder.ExecutionContext.IsRunMode &&
((environments is null || environments.Length == 0) ?
resourceBuilder.ApplicationBuilder.Environment.IsDevelopment() :
environments.Any(resourceBuilder.ApplicationBuilder.Environment.IsEnvironment)
) &&
!resourceBuilder.IsUnderTest());This will make the change affect all project types - e.g. NodeJS, Python, PHP, etc. as well as IIS - and mean we don't have to adjust each resource types' extension method. |
|
You're right - it's not that it's attaching (although an error is weird if I'm not attached myself to the debugger), the issue I was hitting was that a default debug health check was added and therefore never is "healthy". Thoughts? |
|
Well, Can I ask what the scenario you were hitting this in was, as the debug stuff should also be disabled under test mode (which checks for "Aspire.Hosting.Testing" in the stack trace) which should be the case when automating an apphost under test. |
|
With #33 and the change I suggested above, it now works from the Aspire CLI using |
|
My scenario was just running Any of the samples on this branch of the adapters: https://github.com/dotnet/systemweb-adapters/tree/build-samples |
|
btw still working through getting the webapplications.targets relicensed.... |
|
Okay - my suggested change works for dotnet run. I've published an unlisted packages which support this: <PackageReference Include="C3D.Extensions.Aspire.VisualStudioDebug" Version="0.1.42-g0f2568ab6a" />
<PackageReference Include="C3D.Extensions.Aspire.Fluent" Version="0.2.7-g0f2568ab6a" />
<PackageReference Include="C3D.Extensions.VisualStudioDebug" Version="0.1.27-g0f2568ab6a" />Changes are on my fix-aspire-debuggerattached branch. |
|
@twsouthwick Let me know if those work for you, and we can either change this PR to match my branch, or we can close this, and I'll merge my branch. |
|
The message is emitted on the BackgroundService starting, where it waits for resources to start and checks if they have the appropriate annotations. |
|
@twsouthwick Out of interest, before we close this, do you have any idea why the tests are sometimes failing with a wierd polly timeout of 10s (when my tests all setup aspire to have polly timeouts of 30/60/120s). |
|
I'm not sure - I've seen random failures (not always with output) that I'm investigating as well. |



This allows for the common case that when running under debug, things should debug. However, if things are not under debug, probably don't need to attach the debugger. However, if a user wants to force it to, they can still call the .WithDebugger() method manually.