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:
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 screenshot shows 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 an 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:
<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." >
<Analyzer Name="SPCAF.Dependencies" Disabled="false" />
<Analyzer Name="SPCAF.Inventory" Disabled="false">
<Property Key="IgnoredFiles" Value="DocumentFormat.OpenXml.dll;Camlex.NET.dll" />
<Analyzer Name="SPCAF.Rules" Disabled="false">
<Property Key="IgnoredFiles" Value="AjaxControlToolkit.dll" />
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 the 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.