Skip to content

Commit

Permalink
Merge pull request #265 from AArnott/fix196
Browse files Browse the repository at this point in the history
Add AssemblyInfo.GitCommitId property
  • Loading branch information
AArnott authored Dec 10, 2018
2 parents b359fc7 + 0c29aa4 commit 8938831
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
15 changes: 10 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 Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/NerdBank.GitVersioning.Tests/test.prj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<IsVB>false</IsVB>
<RootNamespace>TestNamespace</RootNamespace>
<AssemblyName>TestAssembly</AssemblyName>
<AssemblyTitle>TestAssembly</AssemblyTitle>
Expand All @@ -11,6 +12,8 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<OutputType>Library</OutputType>
<OutputPath>bin\</OutputPath>
<NoWarn Condition=" '$(IsVB)' == 'false' ">$(NoWarn);1607</NoWarn>
<NoWarn Condition=" '$(IsVB)' == 'true' ">$(NoWarn);40010</NoWarn>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
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 8938831

Please sign in to comment.