How to run analysis in a local build

Configure Project File

SPCAF can run the code analysis also during a local build. For this SPCAF comes with a custom MSBuild task and a .targets file.

The MSBuild files are installed by default into "C:\Program Files (x86)\MSBuild\SPCAF". You can reference this path with '$(MSBuildExtensionsPath)\SPCAF\'.

Note: The MSBuild files are installed by default. Do not disable them during installation.

To integrate the analysis into your local build add the following line to your SharePoint project file (.csproj), right after the existing import statements.

<Import
  Condition="'$(BuildingInsideVisualStudio)'=='true' AND Exists('$(MSBuildExtensionsPath)\SPCAF\SPCop.targets')"
  Project="$(MSBuildExtensionsPath)\SPCAF\SPCop.targets" />

Build the project and the analysis will show the errors and warnings in the error list of Visual Studio.

Enable or Disable analysis

You can enable or disable the analysis, e.g. depending on building 'Debug' or 'Release' configuration as follows:

<PropertyGroup>
  <SPCopEnabled>true</SPCopEnabled>
</PropertyGroup>

Change Ruleset for local build

Define the following parameter in the .csproj file to change the ruleset for the analysis:
<PropertyGroup>
  <SPCopSettingsFile>RS01_MinimumRules.spruleset</SPCopSettingsFile>
</PropertyGroup>
comments powered by Disqus