From f9408fed3e054788a663af1f5f646e07fbbe2c63 Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Wed, 22 Feb 2023 01:04:22 +0000 Subject: [PATCH] Reintroduce IsDirty boolean property from 2.3 With the change to ThisAssembly.Constants, we introduced a bug that caused IsDirty to be a string contant, instead of the boolean it was up to 2.3. Closes #243 --- src/Analyzer/GitInfoGenerator.cs | 40 +++++++++++++++++++ .../build/GitInfo.ThisAssembly.targets | 1 - 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/Analyzer/GitInfoGenerator.cs diff --git a/src/Analyzer/GitInfoGenerator.cs b/src/Analyzer/GitInfoGenerator.cs new file mode 100644 index 0000000..aa32c87 --- /dev/null +++ b/src/Analyzer/GitInfoGenerator.cs @@ -0,0 +1,40 @@ +using Microsoft.CodeAnalysis; + +[Generator(LanguageNames.CSharp)] +class GitInfoGenerator : IIncrementalGenerator +{ + public void Initialize(IncrementalGeneratorInitializationContext context) + { + context.RegisterSourceOutput( + context.AdditionalTextsProvider + .Combine(context.AnalyzerConfigOptionsProvider) + .Combine(context.ParseOptionsProvider) + .Collect(), + (c, _) => + { + c.AddSource("ThisAssembly.Git.IsDirty.g", + $$""" + //------------------------------------------------------------------------------ + // + // This code was generated by a tool. + // + // GitInfo: {{ThisAssembly.Info.InformationalVersion}} + // + // Changes to this file may cause incorrect behavior and will be lost if + // the code is regenerated. + // + //------------------------------------------------------------------------------ + partial class ThisAssembly + { + partial class Git + { + /// + /// Gets whether the current repository is dirty. + /// + public static bool IsDirty => bool.TryParse(IsDirtyString, out var dirty) && dirty; + } + } + """); + }); + } +} \ No newline at end of file diff --git a/src/GitInfo/build/GitInfo.ThisAssembly.targets b/src/GitInfo/build/GitInfo.ThisAssembly.targets index 9d9f774..4cb585b 100644 --- a/src/GitInfo/build/GitInfo.ThisAssembly.targets +++ b/src/GitInfo/build/GitInfo.ThisAssembly.targets @@ -37,7 +37,6 @@ BeforeTargets="PrepareConstants" Condition="'$(GitThisAssembly)' == 'true'"> -