This article will guide you through 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 jquery files. This can be achieved by using SPCAF rulesets.
Use SPCAF rulesets to exclude files from analysis
SPCAF rulesets are XML files with the extension .spruleset. They are mainly used to enable or disable analyzers (like rules or metrics) for the analysis. Please refer to Rulesets in our documentation for more details.
Besides the activation/deactivation of rules, the rulesets can be used to define a list of ignored files or folders. This list contains the names of the files/folders which should be ignored during the analysis. The list of ignored files/folders is a string of semicolon-separated filenames or folder paths. See the 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 a 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 careful 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 an XML code similar 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 on how to use rulesets in your analysis.