Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress CA2243 in generated AssemblyInfo file #700

Merged
merged 1 commit into from Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/NerdBank.GitVersioning.Tests/AssemblyInfoTest.cs
Expand Up @@ -57,6 +57,8 @@ public void FSharpGenerator(bool? thisAssemblyClass)
// </auto-generated>
//------------------------------------------------------------------------------

#nowarn ""CA2243""

namespace AssemblyInfo
[<assembly: System.Reflection.AssemblyVersionAttribute(""1.3.0.0"")>]
[<assembly: System.Reflection.AssemblyFileVersionAttribute(""1.3.1.0"")>]
Expand Down Expand Up @@ -133,6 +135,8 @@ public void CSharpGenerator(bool? thisAssemblyClass)
// </auto-generated>
//------------------------------------------------------------------------------

#pragma warning disable CA2243

[assembly: System.Reflection.AssemblyVersionAttribute(""1.3.0.0"")]
[assembly: System.Reflection.AssemblyFileVersionAttribute(""1.3.1.0"")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("""")]
Expand Down Expand Up @@ -188,6 +192,8 @@ public void VisualBasicGenerator(bool? thisAssemblyClass)
' </auto-generated>
'------------------------------------------------------------------------------

#Disable Warning CA2243

<Assembly: System.Reflection.AssemblyVersionAttribute(""1.3.0.0"")>
<Assembly: System.Reflection.AssemblyFileVersionAttribute(""1.3.1.0"")>
<Assembly: System.Reflection.AssemblyInformationalVersionAttribute("""")>
Expand Down
24 changes: 24 additions & 0 deletions src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs
Expand Up @@ -315,6 +315,8 @@ public string BuildCode()
{
this.generator.AddComment(FileHeaderComment);
this.generator.AddBlankLine();
this.generator.AddAnalysisSuppressions();
this.generator.AddBlankLine();
this.generator.EmitNamespaceIfRequired(this.RootNamespace ?? "AssemblyInfo");
this.GenerateAssemblyAttributes();

Expand Down Expand Up @@ -545,6 +547,13 @@ internal CodeGenerator()
this.codeBuilder = new StringBuilder();
}

protected virtual IEnumerable<string> WarningCodesToSuppress { get; } = new string[]
{
"CA2243", // Attribute string literals should parse correctly
};

internal abstract void AddAnalysisSuppressions();

internal abstract void AddComment(string comment);

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

private class FSharpCodeGenerator : CodeGenerator
{
internal override void AddAnalysisSuppressions()
{
this.codeBuilder.AppendLine($"#nowarn {string.Join(" ", this.WarningCodesToSuppress.Select(c => $"\"{c}\""))}");
}

internal override void AddComment(string comment)
{
this.AddCodeComment(comment, "//");
Expand Down Expand Up @@ -636,6 +650,11 @@ internal override void StartThisAssemblyClass()

private class CSharpCodeGenerator : CodeGenerator
{
internal override void AddAnalysisSuppressions()
{
this.codeBuilder.AppendLine($"#pragma warning disable {string.Join(", ", this.WarningCodesToSuppress)}");
}

internal override void AddComment(string comment)
{
this.AddCodeComment(comment, "//");
Expand Down Expand Up @@ -680,6 +699,11 @@ internal override void EndThisAssemblyClass()

private class VisualBasicCodeGenerator : CodeGenerator
{
internal override void AddAnalysisSuppressions()
{
this.codeBuilder.AppendLine($"#Disable Warning {string.Join(", ", this.WarningCodesToSuppress)}");
}

internal override void AddComment(string comment)
{
this.AddCodeComment(comment, "'");
Expand Down