diff --git a/src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs b/src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs index 6ff17c7b..8745d89a 100644 --- a/src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs +++ b/src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs @@ -397,6 +397,8 @@ private void GenerateAssemblyAttributes() this.generator.DeclareAttribute(typeof(AssemblyCopyrightAttribute), this.AssemblyCopyright); } } + + this.generator.EndAssemblyAttributes(); } private List> GetFieldsForThisAssembly() @@ -658,6 +660,10 @@ internal virtual void StartAssemblyAttributes() { } + internal virtual void EndAssemblyAttributes() + { + } + internal abstract void DeclareAttribute(Type type, string arg); internal abstract void StartThisAssemblyClass(); @@ -726,6 +732,11 @@ internal override void StartAssemblyAttributes() this.CodeBuilder.AppendLine($"namespace {this.Namespace}"); } + internal override void EndAssemblyAttributes() + { + this.CodeBuilder.AppendLine("do()"); + } + internal override void DeclareAttribute(Type type, string arg) { this.CodeBuilder.AppendLine($"[]"); @@ -738,7 +749,6 @@ internal override void EndThisAssemblyClass() internal override void StartThisAssemblyClass() { - this.CodeBuilder.AppendLine("do()"); this.CodeBuilder.AppendLine($"#if {CompilerDefinesAroundGeneratedCodeAttribute}"); this.CodeBuilder.AppendLine($"[]"); this.CodeBuilder.AppendLine("#endif"); diff --git a/test/Nerdbank.GitVersioning.Tests/AssemblyInfoTest.cs b/test/Nerdbank.GitVersioning.Tests/AssemblyInfoTest.cs index 43641569..b42d3950 100644 --- a/test/Nerdbank.GitVersioning.Tests/AssemblyInfoTest.cs +++ b/test/Nerdbank.GitVersioning.Tests/AssemblyInfoTest.cs @@ -66,8 +66,8 @@ namespace AssemblyInfo [] [] [] -{(thisAssemblyClass.GetValueOrDefault(true) ? $@"do() -#if NETSTANDARD || NETFRAMEWORK || NETCOREAPP +do() +{(thisAssemblyClass.GetValueOrDefault(true) ? $@"#if NETSTANDARD || NETFRAMEWORK || NETCOREAPP [] #endif #if NET40_OR_GREATER || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER