From 4b0113b570705f6083c60e8522428812fe7f0c63 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Sun, 15 Mar 2020 07:23:22 -0600 Subject: [PATCH] Fix build break introduced in .NET Standard 1.x projects Fixes #452 --- src/NerdBank.GitVersioning.Tests/AssemblyInfoTest.cs | 4 ++++ .../AssemblyVersionInfo.cs | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/NerdBank.GitVersioning.Tests/AssemblyInfoTest.cs b/src/NerdBank.GitVersioning.Tests/AssemblyInfoTest.cs index 46be06bd..09da627d 100644 --- a/src/NerdBank.GitVersioning.Tests/AssemblyInfoTest.cs +++ b/src/NerdBank.GitVersioning.Tests/AssemblyInfoTest.cs @@ -36,6 +36,8 @@ namespace AssemblyInfo do() #if NETSTANDARD || NETFRAMEWORK || NETCOREAPP [] +#endif +#if NETFRAMEWORK || NETCOREAPP || NETSTANDARD2_0 || NETSTANDARD2_1 [] #endif type internal ThisAssembly() = @@ -76,6 +78,8 @@ public void CSharpGenerator() [assembly: System.Reflection.AssemblyInformationalVersionAttribute("""")] #if NETSTANDARD || NETFRAMEWORK || NETCOREAPP [System.CodeDom.Compiler.GeneratedCode(""" + AssemblyVersionInfo.GeneratorName + @""",""" + AssemblyVersionInfo.GeneratorVersion + @""")] +#endif +#if NETFRAMEWORK || NETCOREAPP || NETSTANDARD2_0 || NETSTANDARD2_1 [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] #endif internal static partial class ThisAssembly { diff --git a/src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs b/src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs index 9f0cb40c..ef023a0e 100644 --- a/src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs +++ b/src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs @@ -20,6 +20,7 @@ public class AssemblyVersionInfo : Task /// See https://github.com/dotnet/Nerdbank.GitVersioning/issues/346 /// private const string CompilerDefinesAroundGeneratedCodeAttribute = "NETSTANDARD || NETFRAMEWORK || NETCOREAPP"; + private const string CompilerDefinesAroundExcludeFromCodeCoverageAttribute = "NETFRAMEWORK || NETCOREAPP || NETSTANDARD2_0 || NETSTANDARD2_1"; public static readonly string GeneratorName = ThisAssembly.AssemblyName; public static readonly string GeneratorVersion = ThisAssembly.AssemblyVersion; @@ -519,6 +520,8 @@ internal override void StartThisAssemblyClass() this.codeBuilder.AppendLine("do()"); this.codeBuilder.AppendLine($"#if {CompilerDefinesAroundGeneratedCodeAttribute}"); this.codeBuilder.AppendLine($"[]"); + this.codeBuilder.AppendLine("#endif"); + this.codeBuilder.AppendLine($"#if {CompilerDefinesAroundExcludeFromCodeCoverageAttribute}"); this.codeBuilder.AppendLine("[]"); this.codeBuilder.AppendLine("#endif"); this.codeBuilder.AppendLine("type internal ThisAssembly() ="); @@ -541,6 +544,8 @@ internal override void StartThisAssemblyClass() { this.codeBuilder.AppendLine($"#if {CompilerDefinesAroundGeneratedCodeAttribute}"); this.codeBuilder.AppendLine($"[System.CodeDom.Compiler.GeneratedCode(\"{GeneratorName}\",\"{GeneratorVersion}\")]"); + this.codeBuilder.AppendLine("#endif"); + this.codeBuilder.AppendLine($"#if {CompilerDefinesAroundExcludeFromCodeCoverageAttribute}"); this.codeBuilder.AppendLine("[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]"); this.codeBuilder.AppendLine("#endif"); this.codeBuilder.AppendLine("internal static partial class ThisAssembly {"); @@ -581,10 +586,13 @@ internal override void DeclareAttribute(Type type, string arg) internal override void StartThisAssemblyClass() { - this.codeBuilder.AppendLine($"#If {CompilerDefinesAroundGeneratedCodeAttribute.Replace("||", " Or ")} Then"); + this.codeBuilder.AppendLine($"#If {CompilerDefinesAroundExcludeFromCodeCoverageAttribute.Replace("||", " Or ")} Then"); this.codeBuilder.AppendLine($""); this.codeBuilder.AppendLine(""); this.codeBuilder.AppendLine("Partial Friend NotInheritable Class ThisAssembly"); + this.codeBuilder.AppendLine($"#ElseIf {CompilerDefinesAroundGeneratedCodeAttribute.Replace("||", " Or ")} Then"); + this.codeBuilder.AppendLine($""); + this.codeBuilder.AppendLine("Partial Friend NotInheritable Class ThisAssembly"); this.codeBuilder.AppendLine("#Else"); this.codeBuilder.AppendLine("Partial Friend NotInheritable Class ThisAssembly"); this.codeBuilder.AppendLine("#End If");