diff --git a/build/GitBuildInfo.SourceGenerator.props b/build/GitBuildInfo.SourceGenerator.props index d0c8c1e..30e9d3b 100644 --- a/build/GitBuildInfo.SourceGenerator.props +++ b/build/GitBuildInfo.SourceGenerator.props @@ -1,4 +1,4 @@ - + false diff --git a/build/GitBuildInfo.SourceGenerator.targets b/build/GitBuildInfo.SourceGenerator.targets index 03709be..56de09d 100644 --- a/build/GitBuildInfo.SourceGenerator.targets +++ b/build/GitBuildInfo.SourceGenerator.targets @@ -1,5 +1,4 @@ - - + - + diff --git a/build/GitInfoTask.cs b/build/GitInfoTask.cs index 3037fb5..69b2bcf 100644 --- a/build/GitInfoTask.cs +++ b/build/GitInfoTask.cs @@ -42,10 +42,26 @@ public class GitInfoTask : Task /// public override bool Execute() { + var cache = (GitInfo)BuildEngine4.GetRegisteredTaskObject(this.ProjectDir, RegisteredTaskObjectLifetime.Build); + if (cache is not null) + { + this.GitHead = cache.Head; + this.CommitHash = cache.CommitHash; + this.GitBranch = cache.Branch; + return true; + } + this.GitHead = this.RunGit("describe --all --always --dirty"); this.CommitHash = this.RunGit("rev-parse --short HEAD"); this.GitBranch = this.RunGit("name-rev --name-only HEAD"); this.Log.LogMessage(MessageImportance.High, "Getting build info from git"); + cache = new GitInfo() + { + Head = this.GitHead, + CommitHash = this.CommitHash, + Branch = this.GitBranch, + }; + BuildEngine4.RegisterTaskObject(this.ProjectDir, cache, RegisteredTaskObjectLifetime.Build, false); return true; } @@ -74,5 +90,14 @@ private string RunGit(string arguments) return "Not a git clone or git is not in Path."; } } + + private class GitInfo + { + public string Head { get; set; } + + public string CommitHash { get; set; } + + public string Branch { get; set; } + } } } diff --git a/src/Elskom.GitInformation/stylecop.json b/src/Elskom.GitInformation/stylecop.json index e0c748b..ad835ac 100644 --- a/src/Elskom.GitInformation/stylecop.json +++ b/src/Elskom.GitInformation/stylecop.json @@ -6,7 +6,10 @@ // https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/EnableConfiguration.md "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", - "settings": { + "settings": { + "layoutRules": { + "newlineAtEndOfFile": "require" + }, "documentationRules": { "companyName": "Els_kom org.", "copyrightText": "Copyright (c) 2019-2021, {companyName}\nhttps://github.com/Elskom/\nAll rights reserved.\nlicense: MIT, see LICENSE for more details.", diff --git a/src/GitBuildInfo.SourceGenerator/Directory.Build.props b/src/GitBuildInfo.SourceGenerator/Directory.Build.props index e986b39..938562c 100644 --- a/src/GitBuildInfo.SourceGenerator/Directory.Build.props +++ b/src/GitBuildInfo.SourceGenerator/Directory.Build.props @@ -3,8 +3,8 @@ netstandard2.0 true - 1.0.11 - Fix bug in build task treating MSBuildProjectDirectory as MSBuildProjectFullPath. + 1.0.12 + Fix bug in build task allowing it to run multiple times when multitargeting and when packing nuget packages. Copyright (c) 2021 false