Skip to content

Commit

Permalink
Add AssemblyInfo.GitCommitId property
Browse files Browse the repository at this point in the history
Closes #196
  • Loading branch information
AArnott committed Dec 10, 2018
1 parent f0b9438 commit 37508bf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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));
Expand Down
8 changes: 6 additions & 2 deletions src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ the code is regenerated.

public string AssemblyConfiguration { get; set; }

public string GitCommitId { get; set; }

#if NET461
public override bool Execute()
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
AssemblyCopyright="$(AssemblyCopyright)"
AssemblyCompany="$(AssemblyCompany)"
AssemblyConfiguration="$(Configuration)"
GitCommitId="$(GitCommitId)"
EmitNonVersionCustomAttributes="$(NBGV_EmitNonVersionCustomAttributes)"
/>
<!-- Avoid applying the newly generated AssemblyVersionInfo.cs file to the build
Expand Down

0 comments on commit 37508bf

Please sign in to comment.