Skip to content

Commit 37508bf

Browse files
committed
Add AssemblyInfo.GitCommitId property
Closes #196
1 parent f0b9438 commit 37508bf

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -676,13 +676,15 @@ public async Task PublicRelease_RegEx_SatisfiedByCheckedOutBranch()
676676
}
677677

678678
[Theory]
679-
[InlineData(false, false)]
680-
[InlineData(true, false)]
681-
[InlineData(false, true)]
682-
[InlineData(true, true)]
683-
public async Task AssemblyInfo(bool isVB, bool includeNonVersionAttributes)
679+
[PairwiseData]
680+
public async Task AssemblyInfo(bool isVB, bool includeNonVersionAttributes, bool gitRepo)
684681
{
685682
this.WriteVersionFile();
683+
if (gitRepo)
684+
{
685+
this.InitializeSourceControl();
686+
}
687+
686688
if (isVB)
687689
{
688690
this.MakeItAVBProject();
@@ -738,6 +740,7 @@ public async Task AssemblyInfo(bool isVB, bool includeNonVersionAttributes)
738740
Assert.Equal(result.AssemblyProduct, thisAssemblyClass.GetField("AssemblyProduct", fieldFlags)?.GetValue(null));
739741
Assert.Equal(result.AssemblyCompany, thisAssemblyClass.GetField("AssemblyCompany", fieldFlags)?.GetValue(null));
740742
Assert.Equal(result.AssemblyCopyright, thisAssemblyClass.GetField("AssemblyCopyright", fieldFlags)?.GetValue(null));
743+
Assert.Equal(result.GitCommitId, thisAssemblyClass.GetField("GitCommitId", fieldFlags)?.GetValue(null) ?? string.Empty);
741744

742745
// Verify that it doesn't have key fields
743746
Assert.Null(thisAssemblyClass.GetField("PublicKey", fieldFlags));

src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ the code is regenerated.
6767

6868
public string AssemblyConfiguration { get; set; }
6969

70+
public string GitCommitId { get; set; }
71+
7072
#if NET461
7173
public override bool Execute()
7274
{
@@ -141,7 +143,8 @@ private CodeTypeDeclaration CreateThisAssemblyClass()
141143
{ "AssemblyProduct", this.AssemblyProduct },
142144
{ "AssemblyCopyright", this.AssemblyCopyright },
143145
{ "AssemblyCompany", this.AssemblyCompany },
144-
{ "AssemblyConfiguration", this.AssemblyConfiguration }
146+
{ "AssemblyConfiguration", this.AssemblyConfiguration },
147+
{ "GitCommitId", this.GitCommitId },
145148
}).ToArray());
146149
if (hasKeyInfo)
147150
{
@@ -300,7 +303,8 @@ private void GenerateThisAssemblyClass()
300303
{ "AssemblyProduct", this.AssemblyProduct },
301304
{ "AssemblyCopyright", this.AssemblyCopyright },
302305
{ "AssemblyCompany", this.AssemblyCompany },
303-
{ "AssemblyConfiguration", this.AssemblyConfiguration }
306+
{ "AssemblyConfiguration", this.AssemblyConfiguration },
307+
{ "GitCommitId", this.GitCommitId },
304308
};
305309
if (hasKeyInfo)
306310
{

src/Nerdbank.GitVersioning.Tasks/build/Nerdbank.GitVersioning.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
AssemblyCopyright="$(AssemblyCopyright)"
153153
AssemblyCompany="$(AssemblyCompany)"
154154
AssemblyConfiguration="$(Configuration)"
155+
GitCommitId="$(GitCommitId)"
155156
EmitNonVersionCustomAttributes="$(NBGV_EmitNonVersionCustomAttributes)"
156157
/>
157158
<!-- Avoid applying the newly generated AssemblyVersionInfo.cs file to the build

0 commit comments

Comments
 (0)