How do I integrate StyleCop 4.7 with Visual Studio 2013?

前端 未结 3 1720
不思量自难忘°
不思量自难忘° 2021-01-31 18:01

I really want to use StyleCop with my Visual Studio 2013, but unfortunately it won\'t work. I\'ve installed the 4.7 version from the official site, checking all options, both VS

相关标签:
3条回答
  • 2021-01-31 18:26

    Open Visual studio Open Package Manager Console from TOOLS > LIBRARY PACKAGE MANAGER menu

    Run the following command

    install-package stylecop.msbuild
    

    The above command will download the latest stable required dlls and files and integrate style cop with your project. Build your project and any stylecop errors will be shown in the warnings section.

    If you don't find the package manager for some reason in the above menu, please refer this link for instructions on how to install http://surajdeshpande.wordpress.com/2013/10/18/how-to-install-a-nuget-package-in-visual-studio/

    If you want your build to succeed only if all stylecop errors are fixed, you will need to make some changes to the project file to set a boolean to not treat stylecop errors as warnings.

    Open the .csproj file for your project in notepad, 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>TestProject</RootNamespace>
        <AssemblyName>TestProject</AssemblyName>
        <StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
      </PropertyGroup>
    

    A sample proj file content with <StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings> is shown above.

    The build will be successful only after all sylecop errors are fixed.

    0 讨论(0)
  • 2021-01-31 18:30

    I have integrated the stylecops 4.7 with Visual Studio 2013 (Web) using following steps.

    1. In order to integrate StyleCop with a project, an <Import> needs to be added to the .csproj file (versions and paths might differ):

    If you used the official installer and installed the 'MSBuild integration' component, your <Import> will look like this:

    <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 
    <!-- Your StyleCop <Import> will go here -->
    <Import Project="$(ProgramFiles)\MSBuild\StyleCop\v4.7\StyleCop.targets" />
    

    Note: You need to add the above line in each and every project in your solution.

    1. Copy Settings.StyleCop in the project solution folder from C:\Program Files\StyleCop 4.7 on solution root folder or add as a solution item.

    2. Double click the Settings.StyleCop file as configure the rules. You should be able to use the stylecops in your project.

    0 讨论(0)
  • 2021-01-31 18:31

    Previous answers seems to be deprecated in 2015..

    For VS Community 2013 Update 5:

    1) Install "JetBrains ReSharper Ultimate 2015.2 [En]"

    2) Go to Resharper-> Extensions:

    3) Install Resharper.Stylecop from there

    Update: Ok, for ReSharper Ultimate 10.0.2 + StyleCop by JetBrains 4.8 I get this error: https://resharper-support.jetbrains.com/hc/en-us/community/posts/206009179-StyleCop-integration-with-ReSharper-10-x-VS2015- But there is recommendation to ignore this error. Seems to work after restart VS

    (I also have reSP installed, for Sharepoint code analysis)

    0 讨论(0)
提交回复
热议问题