I'm trying to set up SonarQube to have our coding conventions/rules in it. I'm looking for ideas on how to do this best. We're using C# as our dev language and Visual Studio as our IDE. We have dozens of projects that should all follow the same coding conventions.
Our tools:
Our goals:
Any tips or ideas on how we can achieve our goals?
What I tried
As a test, I installed SonarLint and set it up in Connected Mode. This doesn't seem to check all SonarQube rules. I found, after some searching, that SonarLint only checks for Sonars own rules. Not for 3rd party rules.
I've also looked for what I can use to 'beautify' our code by making it match or coding style rules. The suggestions I found mentioning Roslyn analyzers and editorconfigs.
From my understanding, usage of Roslyn analyzers would mean adding the analyzer dlls to each and every project, which I want to avoid.
And editorconfigs are stored locally which means, if we decide to change some rules, everyone would had to manually update their editorconfig files OR we would have to add editorconfig files to each project. Also at first glance, it looks like editorconfig files aren't very flexible.
We are using Directory.Build.props to customize all project files at once. For example to add analysers:
<Project>
<PropertyGroup>
<Version>93.0.0</Version>
<AssemblyVersion>93.0.0</AssemblyVersion>
<FileVersion>93.0.0</FileVersion>
<Authors>xxxx</Authors>
<Company>xxxx B.V.</Company>
<Product>xxxx Demo</Product>
<LangVersion>12.0</LangVersion>
</PropertyGroup>
<PropertyGroup>
<!-- https://github.com/dotnet/reproducible-builds/blob/main/Documentation/Reproducible-MSBuild/Techniques/DisableImplicitNuGetFallbackFolder.md -->
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
</PropertyGroup>
<Choose>
<When Condition="$(MSBuildProjectName.Contains('Test'))">
<PropertyGroup>
<Nullable>enable</Nullable>
<WarningsAsErrors>NU1605;CS8603</WarningsAsErrors>
<NoWarn>S6562</NoWarn>
</PropertyGroup>
</When>
</Choose>
<ItemGroup>
<PackageReference Include="Custom.CodeAnalyzer" Version="2.0.1" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.14.0.22654" />
</ItemGroup>
</Project>
See Microsoft Learn: https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-directory?view=vs-2022
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With