Skip to content

Commit 1b560ba

Browse files
committed
Merge remote-tracking branch 'origin/master' into dotnetCore
2 parents f2ac21d + f009baa commit 1b560ba

File tree

3 files changed

+48
-30
lines changed

3 files changed

+48
-30
lines changed

src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -590,16 +590,23 @@ public async Task PublicRelease_RegEx_SatisfiedByCheckedOutBranch()
590590
}
591591

592592
[Theory]
593-
[InlineData(false)]
594-
[InlineData(true)]
595-
public async Task AssemblyInfo(bool isVB)
593+
[InlineData(false, false)]
594+
[InlineData(true, false)]
595+
[InlineData(false, true)]
596+
[InlineData(true, true)]
597+
public async Task AssemblyInfo(bool isVB, bool includeNonVersionAttributes)
596598
{
597599
this.WriteVersionFile();
598600
if (isVB)
599601
{
600602
this.MakeItAVBProject();
601603
}
602604

605+
if (includeNonVersionAttributes)
606+
{
607+
this.testProject.AddProperty("NBGV_EmitNonVersionCustomAttributes", "true");
608+
}
609+
603610
var result = await this.BuildAsync("Build", logVerbosity: LoggerVerbosity.Minimal);
604611
string assemblyPath = result.BuildResult.ProjectStateAfterBuild.GetPropertyValue("TargetPath");
605612
string versionFileContent = File.ReadAllText(Path.Combine(this.projectDirectory, result.BuildResult.ProjectStateAfterBuild.GetPropertyValue("VersionSourceFile")));
@@ -619,22 +626,32 @@ public async Task AssemblyInfo(bool isVB)
619626
Assert.Equal(new Version(result.AssemblyVersion), assembly.GetName().Version);
620627
Assert.Equal(result.AssemblyFileVersion, assemblyFileVersion.Version);
621628
Assert.Equal(result.AssemblyInformationalVersion, assemblyInformationalVersion.InformationalVersion);
622-
Assert.Equal(result.AssemblyTitle, assemblyTitle.Title);
623-
Assert.Equal(result.AssemblyProduct, assemblyProduct.Product);
624-
Assert.Equal(result.AssemblyCompany, assemblyCompany.Company);
625-
Assert.Equal(result.AssemblyCopyright, assemblyCopyright.Copyright);
629+
if (includeNonVersionAttributes)
630+
{
631+
Assert.Equal(result.AssemblyTitle, assemblyTitle.Title);
632+
Assert.Equal(result.AssemblyProduct, assemblyProduct.Product);
633+
Assert.Equal(result.AssemblyCompany, assemblyCompany.Company);
634+
Assert.Equal(result.AssemblyCopyright, assemblyCopyright.Copyright);
635+
}
636+
else
637+
{
638+
Assert.Null(assemblyTitle);
639+
Assert.Null(assemblyProduct);
640+
Assert.Null(assemblyCompany);
641+
Assert.Null(assemblyCopyright);
642+
}
626643

627644
const BindingFlags fieldFlags = BindingFlags.Static | BindingFlags.NonPublic;
628645
Assert.Equal(result.AssemblyVersion, thisAssemblyClass.GetField("AssemblyVersion", fieldFlags).GetValue(null));
629646
Assert.Equal(result.AssemblyFileVersion, thisAssemblyClass.GetField("AssemblyFileVersion", fieldFlags).GetValue(null));
630647
Assert.Equal(result.AssemblyInformationalVersion, thisAssemblyClass.GetField("AssemblyInformationalVersion", fieldFlags).GetValue(null));
631648
Assert.Equal(result.AssemblyName, thisAssemblyClass.GetField("AssemblyName", fieldFlags).GetValue(null));
632649
Assert.Equal(result.RootNamespace, thisAssemblyClass.GetField("RootNamespace", fieldFlags).GetValue(null));
633-
Assert.Equal(result.AssemblyTitle, thisAssemblyClass.GetField("AssemblyTitle", fieldFlags).GetValue(null));
634-
Assert.Equal(result.AssemblyProduct, thisAssemblyClass.GetField("AssemblyProduct", fieldFlags).GetValue(null));
635-
Assert.Equal(result.AssemblyCompany, thisAssemblyClass.GetField("AssemblyCompany", fieldFlags).GetValue(null));
636-
Assert.Equal(result.AssemblyCopyright, thisAssemblyClass.GetField("AssemblyCopyright", fieldFlags).GetValue(null));
637650
Assert.Equal(result.AssemblyConfiguration, thisAssemblyClass.GetField("AssemblyConfiguration", fieldFlags).GetValue(null));
651+
Assert.Equal(result.AssemblyTitle, thisAssemblyClass.GetField("AssemblyTitle", fieldFlags)?.GetValue(null));
652+
Assert.Equal(result.AssemblyProduct, thisAssemblyClass.GetField("AssemblyProduct", fieldFlags)?.GetValue(null));
653+
Assert.Equal(result.AssemblyCompany, thisAssemblyClass.GetField("AssemblyCompany", fieldFlags)?.GetValue(null));
654+
Assert.Equal(result.AssemblyCopyright, thisAssemblyClass.GetField("AssemblyCopyright", fieldFlags)?.GetValue(null));
638655

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

src/Nerdbank.GitVersioning.NuGet/build/Nerdbank.GitVersioning.targets

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@
4545
<_NBGV_BuildingRef>$(_NBGV_BuildingTag)</_NBGV_BuildingRef>
4646
<_NBGV_BuildingRef Condition=" '$(_NBGV_BuildingRef)' == '' ">$(_NBGV_BuildingBranch)</_NBGV_BuildingRef>
4747
</PropertyGroup>
48-
<PropertyGroup Condition=" '$(NBGV_DoNotEmitNonVersionCustomAttributes)' != 'true' ">
49-
<_NBGV_AssemblyTitle>$(AssemblyTitle)</_NBGV_AssemblyTitle>
50-
<_NBGV_AssemblyProduct>$(AssemblyProduct)</_NBGV_AssemblyProduct>
51-
<_NBGV_AssemblyCopyright>$(AssemblyCopyright)</_NBGV_AssemblyCopyright>
52-
<_NBGV_AssemblyCompany>$(AssemblyCompany)</_NBGV_AssemblyCompany>
53-
</PropertyGroup>
5448

5549
<Target Name="GetBuildVersion" Returns="$(BuildVersion)">
5650
<Nerdbank.GitVersioning.Tasks.GetBuildVersion
@@ -135,11 +129,13 @@
135129
AssemblyName="$(AssemblyName)"
136130
RootNamespace="$(RootNamespace)"
137131
AssemblyOriginatorKeyFile="$(AssemblyOriginatorKeyFile)"
138-
AssemblyTitle="$(_NBGV_AssemblyTitle)"
139-
AssemblyProduct="$(_NBGV_AssemblyProduct)"
140-
AssemblyCopyright="$(_NBGV_AssemblyCopyright)"
141-
AssemblyCompany="$(_NBGV_AssemblyCompany)"
142-
AssemblyConfiguration="$(Configuration)"/>
132+
AssemblyTitle="$(AssemblyTitle)"
133+
AssemblyProduct="$(AssemblyProduct)"
134+
AssemblyCopyright="$(AssemblyCopyright)"
135+
AssemblyCompany="$(AssemblyCompany)"
136+
AssemblyConfiguration="$(Configuration)"
137+
EmitNonVersionCustomAttributes="$(NBGV_EmitNonVersionCustomAttributes)"
138+
/>
143139
<!-- Avoid applying the newly generated AssemblyVersionInfo.cs file to the build
144140
unless it has changed in order to allow for incremental building. -->
145141
<Nerdbank.GitVersioning.Tasks.CompareFiles OriginalItems="$(VersionSourceFile)" NewItems="$(NewVersionSourceFile)">

src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ the code is regenerated.
4646
[Required]
4747
public string OutputFile { get; set; }
4848

49+
public bool EmitNonVersionCustomAttributes { get; set; }
50+
4951
public string AssemblyName { get; set; }
5052

5153
public string AssemblyVersion { get; set; }
@@ -187,14 +189,17 @@ private IEnumerable<CodeAttributeDeclaration> CreateAssemblyAttributes()
187189
yield return DeclareAttribute(typeof(AssemblyVersionAttribute), this.AssemblyVersion);
188190
yield return DeclareAttribute(typeof(AssemblyFileVersionAttribute), this.AssemblyFileVersion);
189191
yield return DeclareAttribute(typeof(AssemblyInformationalVersionAttribute), this.AssemblyInformationalVersion);
190-
if (!string.IsNullOrEmpty(this.AssemblyTitle))
191-
yield return DeclareAttribute(typeof(AssemblyTitleAttribute), this.AssemblyTitle);
192-
if (!string.IsNullOrEmpty(this.AssemblyProduct))
193-
yield return DeclareAttribute(typeof(AssemblyProductAttribute), this.AssemblyProduct);
194-
if (!string.IsNullOrEmpty(this.AssemblyCompany))
195-
yield return DeclareAttribute(typeof(AssemblyCompanyAttribute), this.AssemblyCompany);
196-
if (!string.IsNullOrEmpty(this.AssemblyCopyright))
197-
yield return DeclareAttribute(typeof(AssemblyCopyrightAttribute), this.AssemblyCopyright);
192+
if (this.EmitNonVersionCustomAttributes)
193+
{
194+
if (!string.IsNullOrEmpty(this.AssemblyTitle))
195+
yield return DeclareAttribute(typeof(AssemblyTitleAttribute), this.AssemblyTitle);
196+
if (!string.IsNullOrEmpty(this.AssemblyProduct))
197+
yield return DeclareAttribute(typeof(AssemblyProductAttribute), this.AssemblyProduct);
198+
if (!string.IsNullOrEmpty(this.AssemblyCompany))
199+
yield return DeclareAttribute(typeof(AssemblyCompanyAttribute), this.AssemblyCompany);
200+
if (!string.IsNullOrEmpty(this.AssemblyCopyright))
201+
yield return DeclareAttribute(typeof(AssemblyCopyrightAttribute), this.AssemblyCopyright);
202+
}
198203
}
199204

200205
private static IEnumerable<CodeMemberField> CreateFields(IReadOnlyDictionary<string, string> namesAndValues)

0 commit comments

Comments
 (0)