Search code examples
c#compiler-warningssuppress-warnings

Is there a way to disable IDE0005_gen warnings?


The following auto-generated .g.cs file has some unused usings and I'd like to silence warnings:

#pragma warning disable IDE0005
#pragma warning disable IDE0005_gen
using System;

However, neither IDE0005 nor IDE0005_gen do work:

enter image description here

Also tried in .editorconfig but without success:

dotnet_diagnostic.ide0005.severity = none
dotnet_diagnostic.ide0005_gen.severity = none

Is there a way to disable IDE warnings in auto-generated files?


Solution

  • In VS 2022 (.NET 6), to disable IDE0005 do one of the following:

    Option 1:

    • In VS menu, click Project
    • Select <project name> Properties
    • Expand Build
    • Click General
    • Under "Implicit global usings", uncheck Enable implicit global usings to be declared by the project SDK

    Option 2:

    In <project name>.csproj (ex: WinFormsApp1.csproj), change

    From:

    <ImplicitUsings>enable</ImplicitUsings>
    

    To:

    <ImplicitUsings>disable</ImplicitUsings>
    

    WinFormsApp1.csproj:

    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <OutputType>WinExe</OutputType>
        <TargetFramework>net6.0-windows</TargetFramework>
        <Nullable>enable</Nullable>
        <UseWindowsForms>true</UseWindowsForms>
        <ImplicitUsings>disable</ImplicitUsings>
      </PropertyGroup>
    
    </Project>
    

    Resources: