How to add stylecop check as a pre-build action to VS2010?
In our project we have added StyleCop task 开发者_如何学Goto be executed after each commit by continuous integration server. The problem is that build often breaks because someone forgets to run Stylecop before commiting code to repository.
The solution will be to execute StyleCop before each VS2010 build. How can I do it? Maybe it is possible to execute pre-build action per whole solution?
It seems you could use MSBuild integration (look here or here), which will make StyleCop checking a part of a build process.
Or you could use some sort of "commit policies" which run StyleCop during the commit and reject the commit if StyleCop checking is not passed. For example, here is one for TFS.
If you are SyleCop rule for all project in local or your teams ?
Hook MSBuild script !!
- Make folder in %ProgramFiles%\MSBuild\v4.0
v4.0 folder name is your .net framework.
ie.
v3.5 for .net framework 3.5
v4.0 for between 4.0 and 4.5...
- then make "Custom.After.Microsoft.Common.targets" and "Custom.Before.Microsoft.Common.targets"
my experience was "Custom.Before.Microsoft.Common.targets" was not working well.
- In "Custom.After.Microsoft.Common.targets" file contained under code
then StyleCop analysis before CoreCompile
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CI_StyleCopPath>$(MSBuildExtensionsPath)\StyleCop\v4.7</CI_StyleCopPath>
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
</PropertyGroup>
<Import Project="$(CI_StyleCopPath)\StyleCop.targets"
Condition=" Exists('$(CI_StyleCopPath)\StyleCop.targets') "/>
<!-- Analysis with StyleCop before build -->
<PropertyGroup>
<BuildDependsOn>
StyleCop; <!-- StyleCop.targets -->
$(BuildDependsOn);
</BuildDependsOn>
</PropertyGroup>
</Project>
See my blog but contents are Korean ;-)
http://xyz37.blog.me/50053407359
精彩评论