From 16be449455d130ac651abada614459b9ae53c099 Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Wed, 8 May 2024 11:29:20 -0300 Subject: [PATCH] Do not emit ThisAssembly.Git.IsDirty when GitThisAssembly is false We missed checking this in the source-generator. Fixes #337 --- src/Analyzer/GitInfoGenerator.cs | 7 ++++++- src/GitInfo/build/GitInfo.ThisAssembly.targets | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Analyzer/GitInfoGenerator.cs b/src/Analyzer/GitInfoGenerator.cs index be188a7..e25cc58 100644 --- a/src/Analyzer/GitInfoGenerator.cs +++ b/src/Analyzer/GitInfoGenerator.cs @@ -11,7 +11,9 @@ public void Initialize(IncrementalGeneratorInitializationContext context) Namespace = c.GlobalOptions.TryGetValue("build_property.ThisAssemblyNamespace", out var ns) && !string.IsNullOrEmpty(ns) ? ns : null, IsDirty = c.GlobalOptions.TryGetValue("build_property.GitIsDirty", out var dirty) - && dirty == "1" ? true : false + && dirty == "1" ? true : false, + NoThisAssembly = c.GlobalOptions.TryGetValue("build_property.GitThisAssembly", out var value) + && bool.TryParse(value, out var thisassembly) && !thisassembly ? true : false }); context.RegisterSourceOutput(ns, @@ -21,6 +23,9 @@ public void Initialize(IncrementalGeneratorInitializationContext context) if (!string.IsNullOrEmpty(state.Namespace)) return; + if (state.NoThisAssembly) + return; + c.AddSource("ThisAssembly.Git.IsDirty.g", $$""" //------------------------------------------------------------------------------ diff --git a/src/GitInfo/build/GitInfo.ThisAssembly.targets b/src/GitInfo/build/GitInfo.ThisAssembly.targets index ae4f7b1..b44555b 100644 --- a/src/GitInfo/build/GitInfo.ThisAssembly.targets +++ b/src/GitInfo/build/GitInfo.ThisAssembly.targets @@ -33,12 +33,15 @@ + + + + + - -