ReSharper 2025.3 Help

Configure compiler warnings

ReSharper includes code inspections that report the most notable compiler warnings, as well as the corresponding quick-fixes for them. To make sure that ReSharper code inspection results correspond to the compiler output and other tools and analyzers, the severity levels of compiler warnings cannot be configured from the editor or through ReSharper options as for ReSharper proprietary inspections.

Instead, there are other ways to suppress compiler warnings, which are summarized below:

Configure with

Compatibility

Granularity

Use it to

.editorconfig

All code analysis rules, not all compiler warnings

File/type/global

Ensure compatibility with Roslyn analyzers; change severity levels of the rules

#pragma directives

All compiler warnings and code analysis rules

Code block/File

Suppress specific warnings locally

Properties in .csproj

All compiler warnings and code analysis rules

Project-wide

Suppress warnings or promote warnings to error at the build level

[SuppressMessage] attribute

All compiler warnings and code analysis rules

Type/Member

Suppress specific warnings in a local scope

GlobalSuppressions.cs

All compiler warnings and code analysis rules

Assembly-wide

Suppress warnings in non-editable or generated code project-wide

Use .editorconfig (preferred for code style and modern analyzers)

The .editorconfig file is a convenient way to configure code styles and diagnostics. It allows you to specify the severity of certain warnings in a consistent and project-wide manner.

You can use EditorConfig keys for all supported warnings in the following format:

dotnet_diagnostic.<ID>.severity = none | silent | suggestion | warning | error

For example:

dotnet_diagnostic.CS8618.severity = none

This method works for compiler warnings starting with C# 8.0 and with Roslyn analysis rules, including those emitted by the compiler itself. For example:

  • Warnings related to nullable references (CS8xxx).

  • Platform compatibility warnings (CS9xxx).

  • Certain documentation or code style diagnostics (e.g., CS1591).

Use #pragma directives in code

You can suppress specific warnings directly in the code using #pragma directives. This is useful for one-off suppressions or limiting the scope of a warning to a specific block of code.

To suppress a highlighted compiler warning, press Alt+Enter and pick the corresponding item.

ReSharper: Disable a compiler warning with '#pragma'

Suppression with #pragma will look as follows:

catch (Exception e) { Console.WriteLine("Caught exception {0}", e); } #pragma warning disable CS1058 // A previous catch clause already catches all exceptions catch #pragma warning restore CS1058 // A previous catch clause already catches all exceptions { Console.WriteLine("Exception fallback"); }

This method works for all compiler warnings (CSxxxx), even those that cannot be configured with .editorconfig.

Configure warnings in the project file (.csproj)

The project file allows you to configure warning behaviors on a project-wide level. Examples include:

Suppress specific warnings

<PropertyGroup> <NoWarn>CS8618;CS1591</NoWarn> </PropertyGroup>

Treat all warnings as errors

<PropertyGroup> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> </PropertyGroup>

Specific warnings as errors or not

<PropertyGroup> <WarningsAsErrors>CS8618</WarningsAsErrors> <WarningsNotAsErrors>CS1591</WarningsNotAsErrors> </PropertyGroup>

Configurations in the .csproj file apply to all CS warnings and will override .editorconfig settings when it comes to build output behavior.

Use [SuppressMessage] attribute

[SuppressMessage] is used to suppress specific compiler warnings and code analysis rules within a particular type or member. It can be used as an alternative to #pragma when you want clear, scoped, and documented suppression. For example:

[SuppressMessage("Compiler", "CS1058", Justification = "Intentional for testing")] static void Test() { try { } catch (Exception e) { Console.WriteLine("Caught exception {0}", e); } catch { Console.WriteLine("Exception fallback"); } }

Use a global suppression file (GlobalSuppressions.cs)

You can suppress any compiler warning or Roslyn code analysis rule across the entire project with a global suppression file. Use attributes to specify which warnings to suppress. For example:

// GlobalSuppressions.cs [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", Justification = "Test methods require underscores for readability." Scope = "namespaceanddescendants", Target = "~N:Company.Product.Tests")]
06 August 2025