Skip to content

Commit dbceee3

Browse files
authored
Merge pull request #700 from dotnet/fix140
Suppress CA2243 in generated AssemblyInfo file
2 parents b050b19 + 5dc86af commit dbceee3

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/NerdBank.GitVersioning.Tests/AssemblyInfoTest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public void FSharpGenerator(bool? thisAssemblyClass)
5757
// </auto-generated>
5858
//------------------------------------------------------------------------------
5959
60+
#nowarn ""CA2243""
61+
6062
namespace AssemblyInfo
6163
[<assembly: System.Reflection.AssemblyVersionAttribute(""1.3.0.0"")>]
6264
[<assembly: System.Reflection.AssemblyFileVersionAttribute(""1.3.1.0"")>]
@@ -133,6 +135,8 @@ public void CSharpGenerator(bool? thisAssemblyClass)
133135
// </auto-generated>
134136
//------------------------------------------------------------------------------
135137
138+
#pragma warning disable CA2243
139+
136140
[assembly: System.Reflection.AssemblyVersionAttribute(""1.3.0.0"")]
137141
[assembly: System.Reflection.AssemblyFileVersionAttribute(""1.3.1.0"")]
138142
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("""")]
@@ -188,6 +192,8 @@ public void VisualBasicGenerator(bool? thisAssemblyClass)
188192
' </auto-generated>
189193
'------------------------------------------------------------------------------
190194
195+
#Disable Warning CA2243
196+
191197
<Assembly: System.Reflection.AssemblyVersionAttribute(""1.3.0.0"")>
192198
<Assembly: System.Reflection.AssemblyFileVersionAttribute(""1.3.1.0"")>
193199
<Assembly: System.Reflection.AssemblyInformationalVersionAttribute("""")>

src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ public string BuildCode()
315315
{
316316
this.generator.AddComment(FileHeaderComment);
317317
this.generator.AddBlankLine();
318+
this.generator.AddAnalysisSuppressions();
319+
this.generator.AddBlankLine();
318320
this.generator.EmitNamespaceIfRequired(this.RootNamespace ?? "AssemblyInfo");
319321
this.GenerateAssemblyAttributes();
320322

@@ -545,6 +547,13 @@ internal CodeGenerator()
545547
this.codeBuilder = new StringBuilder();
546548
}
547549

550+
protected virtual IEnumerable<string> WarningCodesToSuppress { get; } = new string[]
551+
{
552+
"CA2243", // Attribute string literals should parse correctly
553+
};
554+
555+
internal abstract void AddAnalysisSuppressions();
556+
548557
internal abstract void AddComment(string comment);
549558

550559
internal abstract void DeclareAttribute(Type type, string arg);
@@ -586,6 +595,11 @@ protected void AddCodeComment(string comment, string token)
586595

587596
private class FSharpCodeGenerator : CodeGenerator
588597
{
598+
internal override void AddAnalysisSuppressions()
599+
{
600+
this.codeBuilder.AppendLine($"#nowarn {string.Join(" ", this.WarningCodesToSuppress.Select(c => $"\"{c}\""))}");
601+
}
602+
589603
internal override void AddComment(string comment)
590604
{
591605
this.AddCodeComment(comment, "//");
@@ -636,6 +650,11 @@ internal override void StartThisAssemblyClass()
636650

637651
private class CSharpCodeGenerator : CodeGenerator
638652
{
653+
internal override void AddAnalysisSuppressions()
654+
{
655+
this.codeBuilder.AppendLine($"#pragma warning disable {string.Join(", ", this.WarningCodesToSuppress)}");
656+
}
657+
639658
internal override void AddComment(string comment)
640659
{
641660
this.AddCodeComment(comment, "//");
@@ -680,6 +699,11 @@ internal override void EndThisAssemblyClass()
680699

681700
private class VisualBasicCodeGenerator : CodeGenerator
682701
{
702+
internal override void AddAnalysisSuppressions()
703+
{
704+
this.codeBuilder.AppendLine($"#Disable Warning {string.Join(", ", this.WarningCodesToSuppress)}");
705+
}
706+
683707
internal override void AddComment(string comment)
684708
{
685709
this.AddCodeComment(comment, "'");

0 commit comments

Comments
 (0)