1313
1414 public class AssemblyVersionInfo : Task
1515 {
16+ /// <summary>
17+ /// The #if expression that surrounds a <see cref="GeneratedCodeAttribute"/> to avoid a compilation failure when targeting the nano framework.
18+ /// </summary>
19+ /// <remarks>
20+ /// See https://github.com/AArnott/Nerdbank.GitVersioning/issues/346
21+ /// </remarks>
22+ private const string CompilerDefinesAroundGeneratedCodeAttribute = "NETSTANDARD || NETFRAMEWORK || NETCOREAPP" ;
23+
1624 public static readonly string GeneratorName = ThisAssembly . AssemblyName ;
1725 public static readonly string GeneratorVersion = ThisAssembly . AssemblyVersion ;
1826#if NET461
@@ -474,7 +482,9 @@ internal override void EndThisAssemblyClass()
474482 internal override void StartThisAssemblyClass ( )
475483 {
476484 this . codeBuilder . AppendLine ( "do()" ) ;
485+ this . codeBuilder . AppendLine ( $ "#if { CompilerDefinesAroundGeneratedCodeAttribute } ") ;
477486 this . codeBuilder . AppendLine ( $ "[<System.CodeDom.Compiler.GeneratedCode(\" { GeneratorName } \" ,\" { GeneratorVersion } \" )>]") ;
487+ this . codeBuilder . AppendLine ( "#endif" ) ;
478488 this . codeBuilder . AppendLine ( "type internal ThisAssembly() =" ) ;
479489 }
480490 }
@@ -493,7 +503,9 @@ internal override void DeclareAttribute(Type type, string arg)
493503
494504 internal override void StartThisAssemblyClass ( )
495505 {
506+ this . codeBuilder . AppendLine ( $ "#if { CompilerDefinesAroundGeneratedCodeAttribute } ") ;
496507 this . codeBuilder . AppendLine ( $ "[System.CodeDom.Compiler.GeneratedCode(\" { GeneratorName } \" ,\" { GeneratorVersion } \" )]") ;
508+ this . codeBuilder . AppendLine ( "#endif" ) ;
497509 this . codeBuilder . AppendLine ( "internal static partial class ThisAssembly {" ) ;
498510 }
499511
@@ -527,7 +539,9 @@ internal override void DeclareAttribute(Type type, string arg)
527539
528540 internal override void StartThisAssemblyClass ( )
529541 {
542+ this . codeBuilder . AppendLine ( $ "#if { CompilerDefinesAroundGeneratedCodeAttribute } ") ;
530543 this . codeBuilder . AppendLine ( $ "<System.CodeDom.Compiler.GeneratedCode(\" { GeneratorName } \" ,\" { GeneratorVersion } \" )>") ;
544+ this . codeBuilder . AppendLine ( "#endif" ) ;
531545 this . codeBuilder . AppendLine ( "Partial Friend NotInheritable Class ThisAssembly" ) ;
532546 }
533547
0 commit comments