Open joelhoisko opened 3 years ago
I can confirm that the sample problem exists on my machine as well.
$ dotnet --info
.NET SDK (reflecting any global.json):
Version: 5.0.100
Commit: 5044b93829
Runtime Environment:
OS Name: Mac OS X
OS Version: 11.0
OS Platform: Darwin
RID: osx.11.0-x64
Base Path: /usr/local/share/dotnet/sdk/5.0.100/
Host (useful for support):
Version: 5.0.0
Commit: cf258a14b7
.NET SDKs installed:
3.1.405 [/usr/local/share/dotnet/sdk]
5.0.100 [/usr/local/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Thanks for the report. I investigated this further and identified the root cause, and will also provide a temporary workaround. Tagging @jmarolf as this is related to older CodeStyle package shipping in .NET 5.0 SDK.
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
enables the 3.8 version of C# code style analyzers that ship in .NET 5.0 SDK with the build.severity
field for editorconfig code style specification optional, i.e. you can now specify option_name = option_value
instead of option_name = option_value:severity
: https://github.com/dotnet/roslyn/pull/48580. However, this support was not backported to the Code style analyzers shipping in .NET 5.0 SDK, so any code style option entry of the form option_name = option_value
is ignored by the 3.8 version of code style analyzers in the SDKAdd a :warning
suffix to all the editorconfig code style option entries in the repro, i.e.
[*.cs]
dotnet_analyzer_diagnostic.category-style.severity = warning
# allow for implicit 'var' usage
csharp_style_var_elsewhere = true:warning
csharp_style_var_for_built_in_types = true:warning
csharp_style_var_when_type_is_apparent = true:warning
# allow for => in methods and operators
csharp_style_expression_bodied_methods = true:warning
csharp_style_expression_bodied_operators = true:warning
Remove <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
from the project file and instead directly install the C# code style analyzer NuGet package to the project, i.e. add the below PackageReference to your project. Note that you will need to be at least on VS2019 16.9 Preview3 for this package to work.
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="3.9.0-3.final">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
3.9.0-3.final
or later package to be inserted@jmarolf I am assigning this bug to you to help ensure we have inserted the newer code style analyzers into the .NET SDK.
Version Used:
Steps to Reproduce:
.editorconfig
that allows for usingvar
like defined in the documentation for IDE0008 and for the expression bodyallow for implicit 'var' usage
csharp_style_var_elsewhere = true csharp_style_var_for_built_in_types = true csharp_style_var_when_type_is_apparent = true
allow for => in methods and operators
csharp_style_expression_bodied_methods = true csharp_style_expression_bodied_operators = true
dotnet build
Expected Behavior: No
IDE0008
orIDE0022
orIDE0023
warnings as we allowed the rules for them.Actual Behavior:
Not sure if I'm doing something wrong here or what is happening, but I can't allow these rules with the option names. Using
dotnet_diagnostic.<RuleId>.severity
allows me to control their level but not wether or not they are enabled/disabled. Also the documentation seems to be wrong for thevar
rules as my custom rules should already be the default option.Also not sure how many rules this is affecting, these 2 came up in my tests at least.