From 37508bffb343072a478f5713507e4f564bb3e2eb Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Sat, 8 Dec 2018 15:27:19 -0800 Subject: [PATCH 1/2] Add AssemblyInfo.GitCommitId property Closes #196 --- .../BuildIntegrationTests.cs | 13 ++++++++----- .../AssemblyVersionInfo.cs | 8 ++++++-- .../build/Nerdbank.GitVersioning.targets | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs b/src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs index ce1236a9..57ddc0c8 100644 --- a/src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs +++ b/src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs @@ -676,13 +676,15 @@ public async Task PublicRelease_RegEx_SatisfiedByCheckedOutBranch() } [Theory] - [InlineData(false, false)] - [InlineData(true, false)] - [InlineData(false, true)] - [InlineData(true, true)] - public async Task AssemblyInfo(bool isVB, bool includeNonVersionAttributes) + [PairwiseData] + public async Task AssemblyInfo(bool isVB, bool includeNonVersionAttributes, bool gitRepo) { this.WriteVersionFile(); + if (gitRepo) + { + this.InitializeSourceControl(); + } + if (isVB) { this.MakeItAVBProject(); @@ -738,6 +740,7 @@ public async Task AssemblyInfo(bool isVB, bool includeNonVersionAttributes) Assert.Equal(result.AssemblyProduct, thisAssemblyClass.GetField("AssemblyProduct", fieldFlags)?.GetValue(null)); Assert.Equal(result.AssemblyCompany, thisAssemblyClass.GetField("AssemblyCompany", fieldFlags)?.GetValue(null)); Assert.Equal(result.AssemblyCopyright, thisAssemblyClass.GetField("AssemblyCopyright", fieldFlags)?.GetValue(null)); + Assert.Equal(result.GitCommitId, thisAssemblyClass.GetField("GitCommitId", fieldFlags)?.GetValue(null) ?? string.Empty); // Verify that it doesn't have key fields Assert.Null(thisAssemblyClass.GetField("PublicKey", fieldFlags)); diff --git a/src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs b/src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs index cbbe73d8..dae72bfc 100644 --- a/src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs +++ b/src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs @@ -67,6 +67,8 @@ the code is regenerated. public string AssemblyConfiguration { get; set; } + public string GitCommitId { get; set; } + #if NET461 public override bool Execute() { @@ -141,7 +143,8 @@ private CodeTypeDeclaration CreateThisAssemblyClass() { "AssemblyProduct", this.AssemblyProduct }, { "AssemblyCopyright", this.AssemblyCopyright }, { "AssemblyCompany", this.AssemblyCompany }, - { "AssemblyConfiguration", this.AssemblyConfiguration } + { "AssemblyConfiguration", this.AssemblyConfiguration }, + { "GitCommitId", this.GitCommitId }, }).ToArray()); if (hasKeyInfo) { @@ -300,7 +303,8 @@ private void GenerateThisAssemblyClass() { "AssemblyProduct", this.AssemblyProduct }, { "AssemblyCopyright", this.AssemblyCopyright }, { "AssemblyCompany", this.AssemblyCompany }, - { "AssemblyConfiguration", this.AssemblyConfiguration } + { "AssemblyConfiguration", this.AssemblyConfiguration }, + { "GitCommitId", this.GitCommitId }, }; if (hasKeyInfo) { diff --git a/src/Nerdbank.GitVersioning.Tasks/build/Nerdbank.GitVersioning.targets b/src/Nerdbank.GitVersioning.Tasks/build/Nerdbank.GitVersioning.targets index 4c81fda7..90926105 100644 --- a/src/Nerdbank.GitVersioning.Tasks/build/Nerdbank.GitVersioning.targets +++ b/src/Nerdbank.GitVersioning.Tasks/build/Nerdbank.GitVersioning.targets @@ -152,6 +152,7 @@ AssemblyCopyright="$(AssemblyCopyright)" AssemblyCompany="$(AssemblyCompany)" AssemblyConfiguration="$(Configuration)" + GitCommitId="$(GitCommitId)" EmitNonVersionCustomAttributes="$(NBGV_EmitNonVersionCustomAttributes)" />