zoukankan      html  css  js  c++  java
  • StyleCop与MSBuild集成

    MSBuild integration will cause the tool to run automatically whenever the code is built, and StyleCop violations will show up alongside compiler errors in the build output.

    It is possible to set up the build integration so that StyleCop violations will appear as build warnings, or as build errors if so desired.

    Installing MSBuild Files

    To enable build integration, first be sure to select the MSBuild option when installing the tool, as shown in the image below:

    SettingUpMSBuildIntegration_image1.jpg

    This will cause the StyleCop binaries and supporting MSBuild targets files to be installed under the {Program Files}MSBuildStyleCop folder.

    Adding the Import Tag

    Once the StyleCop MSBuild files are installed, the next step is to import the StyleCop targets file into your C# projects. This is done by adding an Import tag to each C# project file.

    For example, to integrate StyleCop to the project SampleProject, open the project file SampleProject.csproj within your favorite text editor. Scroll down to the bottom of the file and add a new tag to import the StyleCop.targets file. This import tag should be added just below the import of Microsoft.CSharp.targets:

    <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    
       ...Contents Removed...
     
    
      <Import Project="$(MSBuildBinPath)Microsoft.CSharp.targets" />
      <Import Project="$(ProgramFiles)MSBuildStyleCopv4.xStyleCop.targets" />  
    
     
    
       ...Contents Removed...
     
    
    </Project>
    

    Save the modified .csproj file. The next time you build this project either within Visual Studio or on the command line, StyleCop will run automatically against all of the C# source files within the project.

    Build Warnings Vs Errors

    By default, StyleCop violations will show up as build warnings. To turn StyleCop violations into build errors, the flag StyleCopTreatErrorsAsWarnings must be set to false. This flag can be set as an environment variable on the machine, or within the build environment command window. Setting the flag this way will cause StyleCop violations to appear as build errors automatically for all projects where StyleCop build integration is enabled.

    Alternately, this flag can be set within the project file for a particular project. Open the .csproj file for your project again, and find the first PropertyGroup section within the file. Add a new tag to set the StyleCopTreatErrorsAsWarnings flag to false. For example:

    <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>SampleProject</RootNamespace>
        <AssemblyName>SampleProject</AssemblyName>
        <StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
      </PropertyGroup>
    

    Team Development

    The configuration described above will suffice to enable StyleCop build integration on an individual development machine. However, development teams working within a well-defined development environment can set up the build integration in a more global way, so that each developer does not have to manually install StyleCop on his machine.

    To do this, copy all of the files from {Program Files}MSBuildStyleCop into a custom folder within your build environment, and check all of these files into your source control system. Next, define an environment variable within your development environment which points to the location of the StyleCop targets file. For example:

    set StyleCopTargets=%enlistmentroot%ExternalToolsStyleCopv4.xStyleCop.targets

    With this configuration in place, it is simply a matter of adding the following import tag to each .csproj file within your development environment:

      <Import Project="$(MSBuildBinPath)Microsoft.CSharp.targets" />
      <Import Project="$(StyleCopTargets)" />
    

    StyleCop will automatically run each time this project is built, no matter who is building the project. There is no need for each developer to install StyleCop manually, since the StyleCop binaries are checked directly into your source control system and are centrally integrated into your build environment.

    Settings files are looked for in the same folder as the .cs file being analysed. If it can't find one there it looks in the parent folder, then its parent and so on up to the root of the drive.

    (Originally from the Microsoft StyleCop blog at http://blogs.msdn.com/b/sourceanalysis/archive/2008/05/24/source-analysis-msbuild-integration.aspx
     
  • 相关阅读:
    网络卖家自曝黑幕 “信用刷手”欺骗你 狼人:
    卡巴斯基:2009年恶意软件发展情况将持续恶化 狼人:
    微软证实云计算平台暂时中断 显现安全弊端 狼人:
    工程目录Maven安装配置及其插件m2e(Eclipse Indigo 和 MyEclipse8.5)的安装配置
    文件系统crondsendmailpostdrop导致Linux定期死掉的完整解决过程实录
    汇编语言处理器面向机器的编程语言 : 汇编语言:如果自己要发明一种编程语言,那么需要做些什么事情呢?
    包解密腾讯手机管家ROOT功能分析
    nullnullhdu 2608
    按钮下载Eclipse Color Theme
    控件学习IOS开源项目(1)之RatingView星级评论控件学习
  • 原文地址:https://www.cnblogs.com/tgcoy/p/3240391.html
Copyright © 2011-2022 走看看