Hi,
I have to do code analysis for my application with custom ruleset.
Is there any way to add custom ruleset in Visual Studio 2019.
In visual studio 2019, there is no option to add ruleset. Please help me on this.

Regards,
Prabs
Hi,
I have to do code analysis for my application with custom ruleset.
Is there any way to add custom ruleset in Visual Studio 2019.
In visual studio 2019, there is no option to add ruleset. Please help me on this.

Regards,
Prabs
Hi @Prabs-7622 , is your issue solved? Please let us know if there is anything that we can help here.
Hello,
For .NET Core or .NET Standard projects this is not supported at project level.
See the Microsoft documentation, follow the steps in the first note.
Edit See the following.

Yes you can have custom rules. It is fully documented here. Note that it does not work like it did for the FxCop (pre Roslyn) analyzers. It is not integrated into the project system.
The general preference is to put your custom rules (or exclusions) in your .editorconfig associated with the project or solution you want it applied to. Converting from a ruleset to editorconfig file is documented in the earlier link. If you really want to continue using a ruleset file then you can do so. For NF projects it works correctly. For .NET Core/Standard/5 projects you have to modify the project file. Again, refer to the docs.
If you need to suppress certain rules then the same options existed as before. For general suppression use .editorconfig. If you need to suppress for specific lines of code then the preference is using an attribute in the code. If that isn't possible then you can continue to use a per-project suppression file.
Finally note that the preference is to get the analyzers from the SDK for .NET 5+ and from NuGet prior to that.
Hi,
I added the following custom rulesets in the Editor config file.
dotnet_diagnostic.CA1822.severity = error
dotnet_diagnostic.CA1800.severity = error
When i try to run code analyzer, I did not get any errors for above mentioned rulesets.
Could you please help me on this issue?

Regards,
Prabs
Code analysis runs at build time. Did you build? Errors show in the error list window. Do you see anything there? Post the code you expect to see the error on. Note that analyzers were posted from fxcop so they may behave a little differently.
Yes I build it..it was not showing anything in error window.
Only CS# related warnings showing not CA# related.
Do i need to install Microsoft.CodeAnalysis.FxCopAnalyzers package from nuGet?
It depends upon what platform you are targeting. Starting with .NET 5 the SDK you build against already has the analyzers enabled. If you are targeting .NET Framework or any version of .NET Core prior to 5 then you need to install Microsoft.CodeAnalysis.NetAnalyzers. The FxCopAnalyzers package is not needed as it is the old rules. Refer to this doc for more information.
Once you upgrade to .NET 5+ you can remove the NuGet package as the SDK is the preferred approach.
11 people are following this question.
How to generate code analysis report in Visual Studio 2019?
How to add custom ruleset for stylecop in Visual Studio 2019?
How to solve Permission Denied issue - Socket Exception in C#.Net core 3.1
How to run .Net Framework Console application on Linux server
How to do encrypt and decrypt data using Cryptography API Next Generation (CNG) in C#?