-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Way to explicitly reference IDE analyzers from project file #34907
Comments
I believe you want this nuget package <PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="3.1.0-beta3-19210-01" /> You can add it to your project using the following command dotnet add package Microsoft.CodeAnalysis.CSharp.CodeStyle --version 3.1.0-beta3-19210-01 --source https://dotnet.myget.org/F/roslyn/api/v3/index.json |
@jmarolf That will work for FormattingAnalyzer, but will not include the others. Currently there is no command line support for any of the IDE analyzers except for IDE0055 (Fix formatting). |
@Youssef1313 Yes, that is correct. This feature is now implemented and analyzers are available in the .NET 5 SDK as well as via a NuGet package: https://docs.microsoft.com/dotnet/fundamentals/code-analysis/overview#code-style-analysis Closing this issue. |
@mavasani are code style/IDE errors expected to be provided via the NuGet package? I see only CA* errors being produced when setting my SDK to .NET Core 3.1. |
@stewartadam If you are using the new SDK-style projects, then you can enable the code style rules on build by following the steps here: https://docs.microsoft.com/dotnet/fundamentals/code-analysis/overview#enable-on-build |
@mavasani, can you confirm those are expected to work from This seems to line up with what I can see in the roslyn-analyzers repo - the only reference to IDE0001 for example is in its own editorconfig. Oddly, I can use |
Microsoft.CodeAnalysis.NetAnalyzers doesn't contain any IDExxxx rules. It indeed only contains CAxxxx rules. |
dotnet-format ships code style analyzers separately from the SDK, which is why it is working for you. |
That's what I've found as well -- I just meant it was odd in that given dotnet-format can detect them with its analyzers, the IDE* rules can be packaged, but they are not included in NetAnalyzers. I feel the docs need clarifying, as the docs talk about "code analysis" (consisting of code quality and code style rules) and mention the NuGet package can be used on older SDKs, but it's never mentioned that code style is dropped from the NuGet package. |
Version Used: VS 2019 Professional (16.0.1)
Is there any way to explicitly reference IDE analyzers from project file (probably with Analyzer tag) so IDE analyzers will be used also while building solution outside of VS only with msbuild? I was discussing this problem in #33558.
Custom analyzers can be activated by adding following tag to csproj (I'm not interested in installing it as VS extension):
IDE analyzers do not have to be included this way. They are present automatically (while building from VS).
Both types (custom and IDE) can be adjusted (=change default severity of analyzers) by ruleset file. Ruleset file is included by following tag in csproj:
When working in VS it works (except the issue #33558 - when IDE analyzers has Warning/Error severity set up they are not breaking a build).
Example (simple program with error, but build succeeds):
My problem probably comes from the very same reason why the build is not broken in example above.
When I build solution just with msbuild as
no error is detected and build succeeds.
What I tried:
The text was updated successfully, but these errors were encountered: