Skip to content

Commit f009baa

Browse files
committed
Always generate ThisAssembly members for assembly metadata
1 parent 3588062 commit f009baa

File tree

3 files changed

+24
-34
lines changed

3 files changed

+24
-34
lines changed

src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -648,21 +648,10 @@ public async Task AssemblyInfo(bool isVB, bool includeNonVersionAttributes)
648648
Assert.Equal(result.AssemblyName, thisAssemblyClass.GetField("AssemblyName", fieldFlags).GetValue(null));
649649
Assert.Equal(result.RootNamespace, thisAssemblyClass.GetField("RootNamespace", fieldFlags).GetValue(null));
650650
Assert.Equal(result.AssemblyConfiguration, thisAssemblyClass.GetField("AssemblyConfiguration", fieldFlags).GetValue(null));
651-
if (includeNonVersionAttributes)
652-
{
653-
654-
Assert.Equal(result.AssemblyTitle, thisAssemblyClass.GetField("AssemblyTitle", fieldFlags).GetValue(null));
655-
Assert.Equal(result.AssemblyProduct, thisAssemblyClass.GetField("AssemblyProduct", fieldFlags).GetValue(null));
656-
Assert.Equal(result.AssemblyCompany, thisAssemblyClass.GetField("AssemblyCompany", fieldFlags).GetValue(null));
657-
Assert.Equal(result.AssemblyCopyright, thisAssemblyClass.GetField("AssemblyCopyright", fieldFlags).GetValue(null));
658-
}
659-
else
660-
{
661-
Assert.Null(thisAssemblyClass.GetField("AssemblyTitle", fieldFlags));
662-
Assert.Null(thisAssemblyClass.GetField("AssemblyProduct", fieldFlags));
663-
Assert.Null(thisAssemblyClass.GetField("AssemblyCompany", fieldFlags));
664-
Assert.Null(thisAssemblyClass.GetField("AssemblyCopyright", fieldFlags));
665-
}
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));
666655

667656
// Verify that it doesn't have key fields
668657
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
@@ -43,12 +43,6 @@
4343
<_NBGV_BuildingRef>$(_NBGV_BuildingTag)</_NBGV_BuildingRef>
4444
<_NBGV_BuildingRef Condition=" '$(_NBGV_BuildingRef)' == '' ">$(_NBGV_BuildingBranch)</_NBGV_BuildingRef>
4545
</PropertyGroup>
46-
<PropertyGroup Condition=" '$(NBGV_EmitNonVersionCustomAttributes)' == 'true' ">
47-
<_NBGV_AssemblyTitle>$(AssemblyTitle)</_NBGV_AssemblyTitle>
48-
<_NBGV_AssemblyProduct>$(AssemblyProduct)</_NBGV_AssemblyProduct>
49-
<_NBGV_AssemblyCopyright>$(AssemblyCopyright)</_NBGV_AssemblyCopyright>
50-
<_NBGV_AssemblyCompany>$(AssemblyCompany)</_NBGV_AssemblyCompany>
51-
</PropertyGroup>
5246

5347
<Target Name="GetBuildVersion" Returns="$(BuildVersion)">
5448
<Nerdbank.GitVersioning.Tasks.GetBuildVersion
@@ -132,11 +126,13 @@
132126
AssemblyName="$(AssemblyName)"
133127
RootNamespace="$(RootNamespace)"
134128
AssemblyOriginatorKeyFile="$(AssemblyOriginatorKeyFile)"
135-
AssemblyTitle="$(_NBGV_AssemblyTitle)"
136-
AssemblyProduct="$(_NBGV_AssemblyProduct)"
137-
AssemblyCopyright="$(_NBGV_AssemblyCopyright)"
138-
AssemblyCompany="$(_NBGV_AssemblyCompany)"
139-
AssemblyConfiguration="$(Configuration)"/>
129+
AssemblyTitle="$(AssemblyTitle)"
130+
AssemblyProduct="$(AssemblyProduct)"
131+
AssemblyCopyright="$(AssemblyCopyright)"
132+
AssemblyCompany="$(AssemblyCompany)"
133+
AssemblyConfiguration="$(Configuration)"
134+
EmitNonVersionCustomAttributes="$(NBGV_EmitNonVersionCustomAttributes)"
135+
/>
140136
<!-- Avoid applying the newly generated AssemblyVersionInfo.cs file to the build
141137
unless it has changed in order to allow for incremental building. -->
142138
<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
@@ -29,6 +29,8 @@ public class AssemblyVersionInfo : Task
2929
[Required]
3030
public string OutputFile { get; set; }
3131

32+
public bool EmitNonVersionCustomAttributes { get; set; }
33+
3234
public string AssemblyName { get; set; }
3335

3436
public string AssemblyVersion { get; set; }
@@ -169,14 +171,17 @@ private IEnumerable<CodeAttributeDeclaration> CreateAssemblyAttributes()
169171
yield return DeclareAttribute(typeof(AssemblyVersionAttribute), this.AssemblyVersion);
170172
yield return DeclareAttribute(typeof(AssemblyFileVersionAttribute), this.AssemblyFileVersion);
171173
yield return DeclareAttribute(typeof(AssemblyInformationalVersionAttribute), this.AssemblyInformationalVersion);
172-
if (!string.IsNullOrEmpty(this.AssemblyTitle))
173-
yield return DeclareAttribute(typeof(AssemblyTitleAttribute), this.AssemblyTitle);
174-
if (!string.IsNullOrEmpty(this.AssemblyProduct))
175-
yield return DeclareAttribute(typeof(AssemblyProductAttribute), this.AssemblyProduct);
176-
if (!string.IsNullOrEmpty(this.AssemblyCompany))
177-
yield return DeclareAttribute(typeof(AssemblyCompanyAttribute), this.AssemblyCompany);
178-
if (!string.IsNullOrEmpty(this.AssemblyCopyright))
179-
yield return DeclareAttribute(typeof(AssemblyCopyrightAttribute), this.AssemblyCopyright);
174+
if (this.EmitNonVersionCustomAttributes)
175+
{
176+
if (!string.IsNullOrEmpty(this.AssemblyTitle))
177+
yield return DeclareAttribute(typeof(AssemblyTitleAttribute), this.AssemblyTitle);
178+
if (!string.IsNullOrEmpty(this.AssemblyProduct))
179+
yield return DeclareAttribute(typeof(AssemblyProductAttribute), this.AssemblyProduct);
180+
if (!string.IsNullOrEmpty(this.AssemblyCompany))
181+
yield return DeclareAttribute(typeof(AssemblyCompanyAttribute), this.AssemblyCompany);
182+
if (!string.IsNullOrEmpty(this.AssemblyCopyright))
183+
yield return DeclareAttribute(typeof(AssemblyCopyrightAttribute), this.AssemblyCopyright);
184+
}
180185
}
181186

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

0 commit comments

Comments
 (0)