-
Notifications
You must be signed in to change notification settings - Fork 22
Custom MSBuild Integration
StyleCop provides a default MSBuild task and targets file which can be used in most common scenarios to integrate StyleCop into an MSBuild-based build environment. This article describes how to write a custom MSBuild task for StyleCop to enable scenarios which are not possible with the default MSBuild task provided with the tool.
To enable advanced MSBuild scenarios, it is necessary to write a custom MSBuild task to wrap the StyleCop toolset. To get started, create a Class Library project in Visual Studio, create a new class within this project, and copy and paste the sample code from below into this class. This provides a default MSBuild task for StyleCop which can be modified to suit your needs.
Code | |
---|---|
namespace MyCustomStyleCopTask { using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; |
Next, create a new file called MyCustomStyleCopTask.targets, and copy and paste the following code into this targets file. You will need to modify the contents of this targets file to match any modifications you make to your custom MSBuild task.
Code | |
---|---|
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <!-- Specify where tasks are implemented. --> <UsingTask AssemblyFile="MyCustomStyleCopTask.dll" TaskName="MyCustomStyleCopTask"/> |
- - SA0102 - Clean Install
- - Download
- - Documentation Rules - Layout Rules - Maintainability Rules - Naming Rules - Ordering Rules - Readability Rules - Spacing Rules - Suppressions
- - Adding a custom StyleCop settings page - Adding custom rule settings - Authoring a custom styleCop rule - Authoring rules metadata - Custom CSharp Language Service - Custom MSBuild Integration - Hosting StyleCop in a Custom Environment - Installing a Custom Rule - Integrating StyleCop Into Build Environments - Integrating StyleCop into MSBuild - Writing Custom Rules for StyleCop