diff --git a/src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs b/src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs index ce1236a9..d7061b14 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)); @@ -1055,6 +1058,8 @@ private void MakeItAVBProject() { var csharpImport = this.testProject.Imports.Single(i => i.Project.Contains("CSharp")); csharpImport.Project = @"$(MSBuildToolsPath)\Microsoft.VisualBasic.targets"; + var isVbProperty = this.testProject.Properties.Single(p => p.Name == "IsVB"); + isVbProperty.Value = "true"; } private struct RestoreEnvironmentVariables : IDisposable diff --git a/src/NerdBank.GitVersioning.Tests/test.prj b/src/NerdBank.GitVersioning.Tests/test.prj index ecd40929..984a3367 100644 --- a/src/NerdBank.GitVersioning.Tests/test.prj +++ b/src/NerdBank.GitVersioning.Tests/test.prj @@ -1,6 +1,7 @@  + false TestNamespace TestAssembly TestAssembly @@ -11,6 +12,8 @@ v4.5 Library bin\ + $(NoWarn);1607 + $(NoWarn);40010 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)" />