-
Notifications
You must be signed in to change notification settings - Fork 34
Description
If a user project enforces code style during build via EnforceCodeStyleInBuild and warnings are treated as errors, then the following issues get flagged and can break the build:
- IDE0010: Add missing cases to switch statement
- IDE0055: Fix formatting
- IDE0058: Remove unused expression value
- IDE0065:
usingdirective placement - IDE0240: Nullable directive is redundant
Steps to Reproduce
These instruction assume that the .NET SDK 8.0.300 is the latest installed.
Ensure the template is installed:
dotnet new install docopt.net.templates::0.1.0
Create a new project using the template:
mkdir demo
cd demo
dotnet new docopt-console -o . -n Demo
Build the project:
dotnet build
It should succeed without errors. Next, create an .editorconfig file with the following content in the same directory:
root = true
[*.cs]
dotnet_analyzer_diagnostic.category-Style.severity = warning
Update Demo.csproj by adding <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild> to the first property group section so that the file's content read as follows:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild> <!-- ADDED -->
</PropertyGroup>
<ItemGroup>
<PackageReference Include="docopt.net" Version="0.8.0" />
<PackageReference Include="ThisAssembly.AssemblyInfo" Version="1.0.9" />
</ItemGroup>
</Project>Re-build the project:
dotnet build
While the build will succeed, it will issue over 300 warnings! If <TreatWarningsAsErrors>true</TreatWarningsAsErrors> is also added to the project file then the project will fail to build.