Create Custom Rules for C# in SonarCloud

hi,
i want to write custom rules for C# in SonarCloud, so need help on how can we create the rule and add in SonarCloud rule list and applies for our project

i tried to navigate on SonarCloud portal but did find place to do so

Hello @mineshrathod-gep,

SonarCloud is a cloud service, so it is not possible to inject custom rules for your own use.

However using SonarQube you can consider writing a custom plugin with custom rules. You can have a look to our extension guide in order to figure out how to proceed. Note that there are also community plugins, maybe other user have the same need than you have.

I hope this helps.

Antoine

1 Like

As said above, you can’t add custom rules to SonarCloud. However, if your project includes any third-party Roslyn analyzers, then any issues raised by will be reported in SonarCloud as generic issues.

This will happen automatically as long as you are using version 4.4 or later of the Scanner for MSBuild. See here for more info.

Generic issues have a few limited described in the link above e.g. you can’ use the SonarCloud UI to configure the set of rules that are run.

Regards,
Duncan

1 Like

Hi, Now I have the same query.
I gone through the below solution as well. But, i am not able to Import third party analyzers.

If you had solution for this, Can you update the steps to proceed.?

Thanks…

You wouldnt be importing the third party analyzer into sonarcloud. You would be including your custom analyzer into your .net project like you do with FxCop/StyleCop/etc.

There are examples of these kinds of analyzers over at github, and a decent article on how to make one. I made two (finished only one of them) of them a few years ago, they were not terribly difficult to make.