1313
1414 public class AssemblyVersionInfo : Task
1515 {
16+ public static readonly string GeneratorName = ThisAssembly . AssemblyName ;
17+ public static readonly string GeneratorVersion = ThisAssembly . AssemblyVersion ;
1618#if NET461
1719 private static readonly CodeGeneratorOptions codeGeneratorOptions = new CodeGeneratorOptions
1820 {
@@ -121,6 +123,12 @@ private CodeTypeDeclaration CreateThisAssemblyClass()
121123 IsPartial = true ,
122124 TypeAttributes = TypeAttributes . NotPublic | TypeAttributes . Sealed ,
123125 } ;
126+
127+ var codeAttributeDeclarationCollection = new CodeAttributeDeclarationCollection ( ) ;
128+ codeAttributeDeclarationCollection . Add ( new CodeAttributeDeclaration ( "System.CodeDom.Compiler.GeneratedCode" ,
129+ new CodeAttributeArgument ( new CodePrimitiveExpression ( GeneratorName ) ) ,
130+ new CodeAttributeArgument ( new CodePrimitiveExpression ( GeneratorVersion ) ) ) ) ;
131+ thisAssembly . CustomAttributes = codeAttributeDeclarationCollection ;
124132
125133 // CodeDOM doesn't support static classes, so hide the constructor instead.
126134 thisAssembly . Members . Add ( new CodeConstructor { Attributes = MemberAttributes . Private } ) ;
@@ -413,7 +421,9 @@ internal override void EndThisAssemblyClass()
413421
414422 internal override void StartThisAssemblyClass ( )
415423 {
416- this . codeBuilder . AppendLine ( "do()\r \n type internal ThisAssembly() =" ) ;
424+ this . codeBuilder . AppendLine ( "do()" ) ;
425+ this . codeBuilder . AppendLine ( $ "[<System.CodeDom.Compiler.GeneratedCode(\" { GeneratorName } \" ,\" { GeneratorVersion } \" )>]") ;
426+ this . codeBuilder . AppendLine ( "type internal ThisAssembly() =" ) ;
417427 }
418428 }
419429
@@ -431,6 +441,7 @@ internal override void DeclareAttribute(Type type, string arg)
431441
432442 internal override void StartThisAssemblyClass ( )
433443 {
444+ this . codeBuilder . AppendLine ( $ "[System.CodeDom.Compiler.GeneratedCode(\" { GeneratorName } \" ,\" { GeneratorVersion } \" )]") ;
434445 this . codeBuilder . AppendLine ( "internal static partial class ThisAssembly {" ) ;
435446 }
436447
@@ -459,6 +470,7 @@ internal override void DeclareAttribute(Type type, string arg)
459470
460471 internal override void StartThisAssemblyClass ( )
461472 {
473+ this . codeBuilder . AppendLine ( $ "<System.CodeDom.Compiler.GeneratedCode(\" { GeneratorName } \" ,\" { GeneratorVersion } \" )>") ;
462474 this . codeBuilder . AppendLine ( "Partial Friend NotInheritable Class ThisAssembly" ) ;
463475 }
464476
0 commit comments