Rulesets are not applies

Hi Nicolas, is there a way that the rulesets can be uploaded to the SonarCloud project. We’ve seen that our Rosyln analysers are being applied with all rules, not those specified in our ruleset.

Kind regards
Ben

Hi @benjones,

Please create a new thread when you encounter an issue. It makes conversations easier to follow and solutions are also easier to find.

Let me check if I understood you correctly, you created a ruleset, configured the build to use this ruleset, analyzed your project and you see rules from the roslyn analyzer appear as external issues in SonarCloud. Is that it?

You can’t upload rulesets to SonarCloud, and there is no need to do so. Roslyn should only execute rules which are in the ruleset, SonarCloud does not filter issues sent by Roslyn. Could you check if the ruleset is enabled during the build of your project?

Kind regards
Nicolas

Thanks Nicolas,

I have now added the ItemGroup Include reference to the ruleset in all csproj files but see within the VSTS build log that it fails to find the files:

/opt/hostedtoolcache/dotnet/sdk/3.0.102/Microsoft.CSharp.CurrentVersion.targets(135,9): warning MSB3884: Could not find rule set file “…/…/…/…/CodeAnalysisRuleSet.ruleset”

I suspect this is why Sonar Cloud is then unable to pick them up. The relative path is the same used within the PropertyGroup so I’m not sure where it is looking.

Do you have any suggestions on getting this to work?

Thanks

I wonder if a similar issue is causing my Pull Requests to register as having 0% code coverage. I can see the following warnings in the Run Code Analysis step:

WARNING: File ‘/home/vsts/work/1/s/CodeAnalysisRuleSet.ruleset’ does not exist.
WARNING: File ‘/home/vsts/.nuget/packages/microsoft.net.test.sdk/16.5.0/build/netcoreapp2.1/Microsoft.NET.Test.Sdk.Program.cs’ is not located under the root directory ‘/home/vsts/work/1/s/Source/DotNet’ and will not be analyzed.
WARNING: File ‘/home/vsts/.nuget/packages/xunit.runner.visualstudio/2.4.1/build/netcoreapp1.0/xunit.runner.visualstudio.dotnetcore.testadapter.dll’ is not located under the root directory ‘/home/vsts/work/1/s/Source/DotNet’ and will not be analyzed.
WARNING: File ‘/home/vsts/.nuget/packages/xunit.runner.visualstudio/2.4.1/build/netcoreapp1.0/xunit.runner.reporters.netcoreapp10.dll’ is not located under the root directory ‘/home/vsts/work/1/s/Source/DotNet’ and will not be analyzed.
WARNING: File ‘/home/vsts/.nuget/packages/xunit.runner.visualstudio/2.4.1/build/netcoreapp1.0/xunit.runner.utility.netcoreapp10.dll’ is not located under the root directory ‘/home/vsts/work/1/s/Source/DotNet’ and will not be analyzed.

Could you confirm if these warnings will result in the code coverage not being picked up?

Thanks
Ben

It seems that this issue is only present when using the Ubuntu build agents. Switching over to use the Windows-latest picked up the ruleset and pushed this through to Sonar. It also picked up some code coverage and pushed this through as well.