@@ -20,6 +20,7 @@ public class AssemblyVersionInfo : Task
2020 /// See https://github.com/dotnet/Nerdbank.GitVersioning/issues/346
2121 /// </remarks>
2222 private const string CompilerDefinesAroundGeneratedCodeAttribute = "NETSTANDARD || NETFRAMEWORK || NETCOREAPP" ;
23+ private const string CompilerDefinesAroundExcludeFromCodeCoverageAttribute = "NETFRAMEWORK || NETCOREAPP || NETSTANDARD2_0 || NETSTANDARD2_1" ;
2324
2425 public static readonly string GeneratorName = ThisAssembly . AssemblyName ;
2526 public static readonly string GeneratorVersion = ThisAssembly . AssemblyVersion ;
@@ -519,6 +520,8 @@ internal override void StartThisAssemblyClass()
519520 this . codeBuilder . AppendLine ( "do()" ) ;
520521 this . codeBuilder . AppendLine ( $ "#if { CompilerDefinesAroundGeneratedCodeAttribute } ") ;
521522 this . codeBuilder . AppendLine ( $ "[<System.CodeDom.Compiler.GeneratedCode(\" { GeneratorName } \" ,\" { GeneratorVersion } \" )>]") ;
523+ this . codeBuilder . AppendLine ( "#endif" ) ;
524+ this . codeBuilder . AppendLine ( $ "#if { CompilerDefinesAroundExcludeFromCodeCoverageAttribute } ") ;
522525 this . codeBuilder . AppendLine ( "[<System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage>]" ) ;
523526 this . codeBuilder . AppendLine ( "#endif" ) ;
524527 this . codeBuilder . AppendLine ( "type internal ThisAssembly() =" ) ;
@@ -541,6 +544,8 @@ internal override void StartThisAssemblyClass()
541544 {
542545 this . codeBuilder . AppendLine ( $ "#if { CompilerDefinesAroundGeneratedCodeAttribute } ") ;
543546 this . codeBuilder . AppendLine ( $ "[System.CodeDom.Compiler.GeneratedCode(\" { GeneratorName } \" ,\" { GeneratorVersion } \" )]") ;
547+ this . codeBuilder . AppendLine ( "#endif" ) ;
548+ this . codeBuilder . AppendLine ( $ "#if { CompilerDefinesAroundExcludeFromCodeCoverageAttribute } ") ;
544549 this . codeBuilder . AppendLine ( "[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]" ) ;
545550 this . codeBuilder . AppendLine ( "#endif" ) ;
546551 this . codeBuilder . AppendLine ( "internal static partial class ThisAssembly {" ) ;
@@ -581,10 +586,13 @@ internal override void DeclareAttribute(Type type, string arg)
581586
582587 internal override void StartThisAssemblyClass ( )
583588 {
584- this . codeBuilder . AppendLine ( $ "#If { CompilerDefinesAroundGeneratedCodeAttribute . Replace ( "||" , " Or " ) } Then") ;
589+ this . codeBuilder . AppendLine ( $ "#If { CompilerDefinesAroundExcludeFromCodeCoverageAttribute . Replace ( "||" , " Or " ) } Then") ;
585590 this . codeBuilder . AppendLine ( $ "<System.CodeDom.Compiler.GeneratedCode(\" { GeneratorName } \" ,\" { GeneratorVersion } \" )>") ;
586591 this . codeBuilder . AppendLine ( "<System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage>" ) ;
587592 this . codeBuilder . AppendLine ( "Partial Friend NotInheritable Class ThisAssembly" ) ;
593+ this . codeBuilder . AppendLine ( $ "#ElseIf { CompilerDefinesAroundGeneratedCodeAttribute . Replace ( "||" , " Or " ) } Then") ;
594+ this . codeBuilder . AppendLine ( $ "<System.CodeDom.Compiler.GeneratedCode(\" { GeneratorName } \" ,\" { GeneratorVersion } \" )>") ;
595+ this . codeBuilder . AppendLine ( "Partial Friend NotInheritable Class ThisAssembly" ) ;
588596 this . codeBuilder . AppendLine ( "#Else" ) ;
589597 this . codeBuilder . AppendLine ( "Partial Friend NotInheritable Class ThisAssembly" ) ;
590598 this . codeBuilder . AppendLine ( "#End If" ) ;
0 commit comments