打开视觉工作室
从“工具”>“库包管理器”菜单打开包管理器控制台
运行以下命令
install-package stylecop.msbuild
上面的命令将下载最新的稳定所需的 dll 和文件,并将样式 cop 与您的项目集成。构建您的项目,任何 stylecop 错误都将显示在警告部分。
如果您由于某种原因在上面的菜单中找不到包管理器,请参阅此链接以获取有关如何安装的说明http://surajdeshpande.wordpress.com/2013/10/18/how-to-install-a-nuget-package-in-visual-studio/ http://surajdeshpande.wordpress.com/2013/10/18/how-to-install-a-nuget-package-in-visual-studio/
如果您希望仅在修复所有 stylecop 错误后构建才能成功,则需要对项目文件进行一些更改以设置一个布尔值,以不将 stylecop 错误视为警告。
在记事本中打开项目的 .csproj 文件,然后找到文件中的第一个 PropertyGroup 部分。添加新标签以将 StyleCopTreatErrorsAsWarnings 标志设置为 false。例如:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{4B4DB6AA-A021-4F95-92B7-B88B5B360228}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TestProject</RootNamespace>
<AssemblyName>TestProject</AssemblyName>
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
</PropertyGroup>
示例项目文件内容为<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
如上所示。
只有修复所有 stylecop 错误后,构建才会成功。