How to: Run SPCAF with MSbuild

MSBuild integration in a TeamBuild (e.g. on Team Foundation Server) is only available in SPCAF Build. The client licenses can use MSBuild or the local build in Visual Studio.

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.

     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:


Change Ruleset for local build

Define the following parameter in the .csproj file to change the ruleset for the analysis:

Have more questions? Submit a request


Please sign in to leave a comment.