Expand Minimize

How to: Exclude files from the analysis

In some cases it is necessary to exclude files from the analysis, e.g. to avoid analysis of 3rd party assemblies or jqery files. This can be achieved by using SPCAF rulesets.

Use SPCAF rulesets to exclude files from analysis

SPCAF rulesets are XML files with extension .spruleset. They are mainly used to enable or disable analyzers (like rules or metrics) for the analysis. Please refer to Rulesets in this documentation for more details.

Besides the activation/deactivation of rules, the rulesets can be used to define a list of ignored files. This list contains the names of the files which should be ignored during the analysis. The list of ignored files is a string of semicolon-separated filenames. See sample below:

Aspose.*.dll;Telerik.*.dll;System.*;*jquery*.js;*knockout*.js;*angular*.js;*tiny*.js;modernizr*.js;respond*.js;bootstrap*.js

The format of a single filename is evaluated as a regular expression. For instance, "jquery*.js" excludes all JavaScript files which start with "jqery".

Exclude files globally or for a certain rule category or rule

Sometimes files should not be excluded completely from the analysis. Instead, the file should be excluded only for a certain rule category or rule. SPCAF rulesets allow the exclusion of files on the following levels

  • Complete exclusion
  • Exclusion for a specific analyzer (e.g. for FxCop)
  • Exclusion for a specific category (e.g. for category "Deployment")
  • Exclusion for a specific rule, metric etc.

Define the list of ignored files

    The list of ignored files is stored in a property "IgnoredFiles" in a ruleset. You can use the following methods to edit this property in a ruleset.

Option 1: Edit SPCAF rulesets in SettingsEditor

SPCAF comes with a separate tool "SPCAF.SettingsEditor.exe" which can be found in the installation directory of SPCAF or in your start menu (depending on your installation). This tool is used to load and edit SPCAF rulesets via a user interface. The following screenshots show the SettingsEditor after the start.

To define a complete exclusion of files refer to the "Global Properties" section (see screenshot below). Here you can define the property "IgnoredFiles" and the list of files for exclusion. If the property is not present add the property by clicking the "Add" button.

To define the list of ignored files on an analyzer, category or rule select in the treeview in the center of the SettingsEditor, on which level you want to exclude files from the analysis, e.g. select category "Deployment" (see sample below). If you want to exclude file completely select nothing in the treeview.

After defining the level for exclusion refer to the section "Configuration Values" on the right side of the application (see screenshot below). Here you can define the property "IgnoredFiles" and the list of files for exclusion. If the property is not present add the property by clicking the "Add" button.

Option 2: Edit SPCAF rulesets in XML editor

If you are firm with editing XML code you can open a SPCAF ruleset (.spruleset) in your preferred XML editor.

Important: Be carefully when editing SPCAF rulesets. If the XML format is not correct SPCAF cannot load the ruleset during the analysis.

Open the SPCAF ruleset in an XML editor. You will see a XML code similiar to the following sample:

<?xml version="1.0"?>
<SPCAFSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  Name="Extended Recommended Settings"
  Description="These settings focus on a detailed check of your code." >
  <Properties>
    <Property
      Key="IgnoredFiles"
      Value="Aspose.*.dll;Telerik.*.dll;System.*;*jquery*.js;*knockout*.js;*angular*.js;*tiny*.js;modernizr*.js;respond*.js;bootstrap*.js" />
  </Properties>
  <Analyzers>
    <Analyzer Name="SPCAF.Dependencies" Disabled="false" />
    <Analyzer Name="SPCAF.Inventory" Disabled="false">
      <Properties>
        <Property Key="IgnoredFiles" Value="DocumentFormat.OpenXml.dll;Camlex.NET.dll" />
      </Properties>
    </Analyzer>
    <Analyzer Name="SPCAF.Rules" Disabled="false">
      <RuleGroups>
        <RuleGroup Name="SPCAF.Rules.DeploymentGroup">
          <Properties>
            <Property Key="IgnoredFiles" Value="AjaxControlToolkit.dll" />
          </Properties>
        </RuleGroup>
      <RuleGroups>
    </Analyzer>
  </Analyzers>
</SPCAFSettings>

In the sample above you see:

  • a global exclusion of files in the first property "IgnoredFiles"
  • an exclusion for analyzer "SPCAF.Inventory"
  • an exclusion for category "Deployment"

Use the ruleset in your analysis

Finally save the ruleset and use the ruleset for your analysis. Refer to section "Rulesets" for more information how to use rulesets in your analysis.

Disclaimer: The views and opinions expressed in this documentation and in SPCAF do not necessarily reflect the opinions and recommendations of Microsoft or any member of Microsoft. SPCAF and RENCORE are registered trademarks of Rencore. All other trademarks, service marks, collective marks, copyrights, registered names, and marks used or cited by this documentation are the property of their respective owners.