Skip to content

Commit 9f56443

Browse files
authored
Add GEneratorName & Version as public static properties
1 parent c4a6bc4 commit 9f56443

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
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
{
@@ -119,13 +121,13 @@ private CodeTypeDeclaration CreateThisAssemblyClass()
119121
{
120122
IsClass = true,
121123
IsPartial = true,
122-
TypeAttributes = TypeAttributes.NotPublic | TypeAttributes.Sealed | TypeAttributes.Abstract,
124+
TypeAttributes = TypeAttributes.NotPublic | TypeAttributes.Sealed,
123125
};
124126

125127
var codeAttributeDeclarationCollection = new CodeAttributeDeclarationCollection();
126128
codeAttributeDeclarationCollection.Add(new CodeAttributeDeclaration("System.CodeDom.Compiler.GeneratedCode",
127-
new CodeAttributeArgument(new CodePrimitiveExpression(ThisAssembly.AssemblyName)),
128-
new CodeAttributeArgument(new CodePrimitiveExpression(ThisAssembly.AssemblyVersion))));
129+
new CodeAttributeArgument(new CodePrimitiveExpression(GeneratorName)),
130+
new CodeAttributeArgument(new CodePrimitiveExpression(GeneratorVersion))));
129131
thisAssembly.CustomAttributes = codeAttributeDeclarationCollection;
130132

131133
// CodeDOM doesn't support static classes, so hide the constructor instead.
@@ -420,7 +422,7 @@ internal override void EndThisAssemblyClass()
420422
internal override void StartThisAssemblyClass()
421423
{
422424
this.codeBuilder.AppendLine("do()");
423-
this.codeBuilder.AppendLine($"[<System.CodeDom.Compiler.GeneratedCode(\"{ThisAssembly.AssemblyName}\",\"{ThisAssembly.AssemblyVersion}\")>]");
425+
this.codeBuilder.AppendLine($"[<System.CodeDom.Compiler.GeneratedCode(\"{GeneratorName}\",\"{GeneratorVersion}\")>]");
424426
this.codeBuilder.AppendLine("type internal ThisAssembly() =");
425427
}
426428
}
@@ -439,7 +441,7 @@ internal override void DeclareAttribute(Type type, string arg)
439441

440442
internal override void StartThisAssemblyClass()
441443
{
442-
this.codeBuilder.AppendLine($"[System.CodeDom.Compiler.GeneratedCode(\"{ThisAssembly.AssemblyName}\",\"{ThisAssembly.AssemblyVersion}\")]");
444+
this.codeBuilder.AppendLine($"[System.CodeDom.Compiler.GeneratedCode(\"{GeneratorName}\",\"{GeneratorVersion}\")]");
443445
this.codeBuilder.AppendLine("internal static partial class ThisAssembly {");
444446
}
445447

@@ -468,7 +470,7 @@ internal override void DeclareAttribute(Type type, string arg)
468470

469471
internal override void StartThisAssemblyClass()
470472
{
471-
this.codeBuilder.AppendLine($"<System.CodeDom.Compiler.GeneratedCode(\"{ThisAssembly.AssemblyName}\",\"{ThisAssembly.AssemblyVersion}\")>");
473+
this.codeBuilder.AppendLine($"<System.CodeDom.Compiler.GeneratedCode(\"{GeneratorName}\",\"{GeneratorVersion}\")>");
472474
this.codeBuilder.AppendLine("Partial Friend NotInheritable Class ThisAssembly");
473475
}
474476

0 commit comments

Comments
 (0)