Skip to content

Commit 8938831

Browse files
authored
Merge pull request #265 from AArnott/fix196
Add AssemblyInfo.GitCommitId property
2 parents b359fc7 + 0c29aa4 commit 8938831

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs

Lines changed: 10 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));
@@ -1055,6 +1058,8 @@ private void MakeItAVBProject()
10551058
{
10561059
var csharpImport = this.testProject.Imports.Single(i => i.Project.Contains("CSharp"));
10571060
csharpImport.Project = @"$(MSBuildToolsPath)\Microsoft.VisualBasic.targets";
1061+
var isVbProperty = this.testProject.Properties.Single(p => p.Name == "IsVB");
1062+
isVbProperty.Value = "true";
10581063
}
10591064

10601065
private struct RestoreEnvironmentVariables : IDisposable

src/NerdBank.GitVersioning.Tests/test.prj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
4+
<IsVB>false</IsVB>
45
<RootNamespace>TestNamespace</RootNamespace>
56
<AssemblyName>TestAssembly</AssemblyName>
67
<AssemblyTitle>TestAssembly</AssemblyTitle>
@@ -11,6 +12,8 @@
1112
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1213
<OutputType>Library</OutputType>
1314
<OutputPath>bin\</OutputPath>
15+
<NoWarn Condition=" '$(IsVB)' == 'false' ">$(NoWarn);1607</NoWarn>
16+
<NoWarn Condition=" '$(IsVB)' == 'true' ">$(NoWarn);40010</NoWarn>
1417
</PropertyGroup>
1518
<ItemGroup>
1619
<Reference Include="System" />

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)