Search code examples
.netsonarqubefxcop

Import custom FxCop rules to sonar


Please help me,

Custom assembly : C:\Program Files (x86)\Microsoft FxCop 1.35\Rules\my\DOTNET.dll

Rules file : D:\SONAR\extensions\rules\fxcop\DOTNET.xml

I click on restore profile and backup this file: export.xml -- after import is 0 rules

What is wrong?

Thanks for help. David Molcan

Here is DOTNET.xml

<rules>
<rule key="DOTNETCodeWritingGuidlinesForClassesFinalizerWithIDisposable">
<name>
<![CDATA[ La méthode doit avoir une casse correct. ]]>
</name>
<configKey>
<![CDATA[
DOTNETCodeWritingGuidlinesForClassesFinalizerWithIDisposable@C:\Program Files (x86)\Microsoft FxCop 1.35\Rules\my\DOTNET.dll
]]>
</configKey>
<category name="Maintainability"/>
<description>
<![CDATA[ La méthode doit avoir une casse correct. ]]>
</description>
</rule>
</rules>

Here is export.xml

<!--  Generated by SonarQube  -->
<profile>
    <name>Sonar way2</name>
    <language>cs</language>
<FxCopProject Version="1.36">
<ProjectOptions>
<SharedProject>True</SharedProject>
<SaveMessages>
<Project NewOnly="False" Status="Active, Excluded"/>
<Report NewOnly="False" Status="Active"/>
</SaveMessages>
<ProjectFile Deterministic="True" SaveByRuleGroup="" DefaultRuleCheck="True" DefaultTargetCheck="True" Compress="True"/>
<EnableMultithreadedLoad>True</EnableMultithreadedLoad>
<EnableMultithreadedAnalysis>True</EnableMultithreadedAnalysis>
<SourceLookup>True</SourceLookup>
<AnalysisExceptionsThreshold>10</AnalysisExceptionsThreshold>
<RuleExceptionsThreshold>1</RuleExceptionsThreshold>
<Spelling Locale="en-US"/>
<OverrideRuleVisibilities>False</OverrideRuleVisibilities>
<CustomDictionaries SearchProjectDir="True" SearchUserProfile="True" SearchFxCopDir="True"/>
<IgnoreGeneratedCode>False</IgnoreGeneratedCode>
</ProjectOptions>
<Rules>
<RuleFiles>
<RuleFile AllRulesEnabled="False" Enabled="True" Name="C:\Program Files (x86)\Microsoft FxCop 1.35\Rules\my\DOTNET.dll">
<Rule Enabled="True" Name="DOTNETCodeWritingGuidlinesForClassesFinalizerWithIDisposable" SonarPriority="major"/>
</RuleFile>
</RuleFiles>
</Rules>
</FxCopProject>
</profile>

Solution

  • FxCop 1.35 is very old and no longer officially supported by the SonarQube C# plugin, even though it might still work. See http://blogs.msdn.com/b/codeanalysis/archive/2010/03/26/how-to-write-custom-static-code-analysis-rules-and-integrate-them-into-visual-studio-2010.aspx for details on how to implement FxCop custom rules.

    Since the C# 3.2 plugin, custom FxCop rules are supported again. To use them, simply copy the rule template "Template for custom FxCop rules" (key CustomRuleTemplate) as many times as required and specify the CheckId of each of your custom rume.

    If you are still using version 2.1 of the C# plugin, you might want to read http://docs.codehaus.org/x/EIBMDg before upgrading to 3.x.