Skip to content

WarningLevel is not set to match AnalysisLevel #41295

Open
@sliekens

Description

@sliekens

Type of issue

Other (describe below)

Description

In the WarningLevel section (link), there is a note about the use of AnalysisLevel which suggests that setting AnalysisLevel will also set WarningLevel to match.

However, I think this information is incorrect or misleading.

image

Example project file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <AnalysisLevel>none</AnalysisLevel>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
  </PropertyGroup>

</Project>

Example Program.cs:

class program
{
    static void Main() { }
}

Output of dotnet build:

MSBuild version 17.9.8+b34f75857 for .NET
  Determining projects to restore...
  Restored /proof/proof.csproj (in 57 ms).
/proof/Program.cs(1,7): error CS8981: The type name 'program' only contains lower-cased ascii characters. Such names may become reserved for the language. [/proof/proof.csproj]

Build FAILED.

/proof/Program.cs(1,7): error CS8981: The type name 'program' only contains lower-cased ascii characters. Such names may become reserved for the language. [/proof/proof.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.75

Why does the build still report a warning wave 7 error?
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/warning-waves#cs8981---the-type-name-only-contains-lower-cased-ascii-characters

I expected warning wave 7 to be disabled by setting AnalysisLevel to none in my csproj ❓

The warning disappears when I run dotnet build --no-incremental /p:WarningLevel=6 or lower.

Page URL

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/errors-warnings#analysis-level

Content source URL

https://github.com/dotnet/docs/blob/main/docs/csharp/language-reference/compiler-options/errors-warnings.md

Document Version Independent Id

e57ac82b-307e-163b-8172-52644b3a6baa

Article author

@BillWagner

Metadata

  • ID: 26ef35c2-6df4-26f8-32b2-9b50eb76c037
  • Service: dotnet-csharp
  • Sub-service: lang-reference

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions