您可以将 StyleCop 设置文件 (Settings.StyleCop) 放在 VS 解决方案所在的根目录中(当然也将其置于源代码管理之下)。 StyleCop 知道如何自动找到该文件(通过查找目录树)。 这样您就可以为每个解决方案进行自定义设置。
我们关闭了某些我们认为不太实用的 StyleCop 规则。
这样,StyleCop 将集成到您的编译步骤中,因此它将成为 CI 构建的一部分。
Some points for using StyleCop in general:
You don't need to have StyleCop installed on your (or the build) machine - simply add StyleCop's binaries to your source control (about 1.5 MB of stuff)
Then simply add the relative reference to your project files, like this (I left out < and >):
We treat all StyleCop warnings as errors using the StyleCopTreatErrorsAsWarnings setting in the project file.
For legacy projects, you can use the tool provided by Microsoft to automatically set all existing source files to ignore.
You can put the StyleCop settings file (Settings.StyleCop) in the root directory where your VS solution is (and of course place it under the source control). StyleCop knows how to find this file automatically (by loooking up the directory tree). This way you can have custom settings for each solution.
We turned off certain StyleCop rules which we think aren't very practical to follow.
This way StyleCop will be integrated in your compile step and as such it will become a part of the CI build.
basically you set a couple of environment variables up, reference them in all the .csproj files so that you can cater for different working directories for each individual developer, install the StyleCop MSBuild components on the build machine and you're off. No changes to the team build required.
发布评论
评论(3)
转到 Visual Studio,右键单击“解决方案”>“解决方案” 管理 Nuget 包 > 安装StyleCop.MSBuild。
就是这样 =)
Go to Visual Studio, right click Solution > Manage Nuget Packages > Install StyleCop.MSBuild.
That's it =)
一般使用 StyleCop 的一些要点:
然后只需添加相对引用到您的项目文件,如下所示(我省略了 < 和 >):
Import Project="..\..\lib\Microsoft StyleCop\Microsoft.StyleCop.Targets"
我们使用项目文件中的
StyleCopTreatErrorsAsWarnings
设置将所有 StyleCop 警告视为错误。Settings.StyleCop
) 放在 VS 解决方案所在的根目录中(当然也将其置于源代码管理之下)。 StyleCop 知道如何自动找到该文件(通过查找目录树)。 这样您就可以为每个解决方案进行自定义设置。这样,StyleCop 将集成到您的编译步骤中,因此它将成为 CI 构建的一部分。
Some points for using StyleCop in general:
Then simply add the relative reference to your project files, like this (I left out < and >):
Import Project="..\..\lib\Microsoft StyleCop\Microsoft.StyleCop.Targets"
We treat all StyleCop warnings as errors using the
StyleCopTreatErrorsAsWarnings
setting in the project file.Settings.StyleCop
) in the root directory where your VS solution is (and of course place it under the source control). StyleCop knows how to find this file automatically (by loooking up the directory tree). This way you can have custom settings for each solution.This way StyleCop will be integrated in your compile step and as such it will become a part of the CI build.
我们在以下文章中成功地在几个项目中使用了该方法...
http://blogs.msdn.com/sourceanalysis/pages/source-analysis-msbuild-integration.aspx
http://blogs. msdn.com/sourceanalysis/archive/2008/11/11/introducing-stylecop-on-legacy-projects.aspx
基本上,您设置了几个环境变量,在所有 .csproj 文件中引用它们,以便您可以满足每个开发人员的不同工作目录,在构建机器上安装 StyleCop MSBuild 组件就可以了。 无需更改团队建设。
We use the approach in the following articles successfully on a couple of projects...
http://blogs.msdn.com/sourceanalysis/pages/source-analysis-msbuild-integration.aspx
http://blogs.msdn.com/sourceanalysis/archive/2008/11/11/introducing-stylecop-on-legacy-projects.aspx
basically you set a couple of environment variables up, reference them in all the .csproj files so that you can cater for different working directories for each individual developer, install the StyleCop MSBuild components on the build machine and you're off. No changes to the team build required.