roslyn: Suppressing one IDExxxx rule from a multi-rule EditorConfig setting is not possible if EnforceCodeStyleInBuild is enabled
Version Used: VS 17.10.1, SDK 8.0.300
Steps to Reproduce:
- Create a .NET 8 console app project with this code:
int[] a = new[] { 1, 2 };
int[] b = new[] { 1, 2 }.ToArray();
- Add this EditorConfig file:
root = true
[*.cs]
dotnet_style_prefer_collection_expression = when_types_loosely_match:warning
dotnet_diagnostic.IDE0305.severity = none
- Check which warnings are shown in the Visual Studio error list. See that it correctly only shows IDE0300 for the first line, and no warning for the second line.
- Add
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>to the csproj file. - Check the warnings in the Visual Studio error list again.
Diagnostic Id:
"IDE0305: Use collection expression for fluent"
Expected Behavior: Only the IDE0300 warning for the first line is shown.
Actual Behavior: The IDE0305 warning is shown for the second line.
Additional information:
The second warning shows up without building the project. So the setting EnforceCodeStyleInBuild seems to have some effect even without building.
Similar to #72094 (fixed by #72238), but only when EnforceCodeStyleInBuild is enabled.
Related to https://github.com/dotnet/roslyn/issues/52991#issuecomment-1960692440
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (9 by maintainers)
It’s not desired, but it’s a situation we know happens. We are working on a solution in https://github.com/dotnet/sdk/issues/41791.