From 93af1ee8420abc9312a1c1088d5b292860dd7bf3 Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Tue, 6 Aug 2024 15:27:45 -0300 Subject: [PATCH] Ignore design-time build value when debugging generator This allows running F5 on the generator project and troubleshoot issues. By checking for an already attached debugger, we can debug also scenarios of code generation where the roslyn component starts it with DTB=true. --- .../Orleans.CodeGenerator.csproj | 1 + src/Orleans.CodeGenerator/OrleansSourceGenerator.cs | 13 +++++++------ .../Properties/launchSettings.json | 8 ++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 src/Orleans.CodeGenerator/Properties/launchSettings.json diff --git a/src/Orleans.CodeGenerator/Orleans.CodeGenerator.csproj b/src/Orleans.CodeGenerator/Orleans.CodeGenerator.csproj index af653ca935..c05d097cd9 100644 --- a/src/Orleans.CodeGenerator/Orleans.CodeGenerator.csproj +++ b/src/Orleans.CodeGenerator/Orleans.CodeGenerator.csproj @@ -10,6 +10,7 @@ true false true + true diff --git a/src/Orleans.CodeGenerator/OrleansSourceGenerator.cs b/src/Orleans.CodeGenerator/OrleansSourceGenerator.cs index b23ba45ba4..20ca0fa862 100644 --- a/src/Orleans.CodeGenerator/OrleansSourceGenerator.cs +++ b/src/Orleans.CodeGenerator/OrleansSourceGenerator.cs @@ -23,18 +23,19 @@ public void Execute(GeneratorExecutionContext context) return; } - if (context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.orleans_designtimebuild", out var isDesignTimeBuild) - && string.Equals("true", isDesignTimeBuild, StringComparison.OrdinalIgnoreCase)) - { - return; - } - if (context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.orleans_attachdebugger", out var attachDebuggerOption) && string.Equals("true", attachDebuggerOption, StringComparison.OrdinalIgnoreCase)) { Debugger.Launch(); } + if (!Debugger.IsAttached && + context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.orleans_designtimebuild", out var isDesignTimeBuild) + && string.Equals("true", isDesignTimeBuild, StringComparison.OrdinalIgnoreCase)) + { + return; + } + var options = new CodeGeneratorOptions(); if (context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.orleans_immutableattributes", out var immutableAttributes) && immutableAttributes is { Length: > 0 }) { diff --git a/src/Orleans.CodeGenerator/Properties/launchSettings.json b/src/Orleans.CodeGenerator/Properties/launchSettings.json new file mode 100644 index 0000000000..3b0cf0fa23 --- /dev/null +++ b/src/Orleans.CodeGenerator/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "Roslyn": { + "commandName": "DebugRoslynComponent", + "targetProject": "..\\..\\test\\Orleans.Serialization.UnitTests\\Orleans.Serialization.UnitTests.csproj" + } + } +} \ No newline at end of file