Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8869681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:32:24+00:00 2026-06-14T17:32:24+00:00

We’re moving to Visual Studio Professional 2012, and now have access to Code Analysis.

  • 0

We’re moving to Visual Studio Professional 2012, and now have access to Code Analysis.

Before, we used FxCop and passed a parameter of SourceControlPath\OurFxCopSharedProject.FxCop. We also added a CustomDictionary.xml to the (source controlled) folder containing FxCop.exe. This worked great, as we use many industry-specific terms and have standardized our analysis rules.

In VS 2012, it appears that the Code Analysis Dictionary must be applied to each project and the Rule Set must be specified for each project.

Is there a way to default both existing and new projects to our standard .ruleset and CustomDictionary.xml (rather than Microsoft Minimum Recommended Rules and the standard dictionary)? We have hundreds of solutions and many more projects.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:32:26+00:00Added an answer on June 14, 2026 at 5:32 pm

    Yes, well at least you can for VS2010, and I presume it’ll work the same for VS2012.

    I followed the details as described in this blog post, and it worked great for me.

    There was also an issue in VS2010 whereby the ruleset configured for the first project built became the ruleset for all projects, regardless of what was configured. This didn’t work well for me because I’ve relaxed the rules for our unit test projects. I presume (hope) that its fixed in VS2012, but if it isn’t this procedure also provides a workaround for that.


    Update

    The blog no longer exists. I found the below at http://web.archive.org/web/20140531211137/http://kentb.blogspot.co.nz/2011_01_01_archive.html.

    The sample solution can still be found at https://onedrive.live.com/?cid=328ba01b2a22de20&id=328BA01B2A22DE20%21178&authkey=!ALAeFtsfPqgdMCk

    All credit goes to Kent Boogaart


    Code Analysis without Visual Studio 2010

    This post provides step-by-step instructions on how to integrate Visual Studio 2010’s code analysis into your build. If you’ve not yet done so, please read my first post for an overview of what will be achieved. If you’d prefer, you can integrate Visual Studio 2008’s code analysis by following the instructions in my previous post. Whilst you will need a machine with Visual Studio 2010 installed, this won’t be a requirement for building your project once it’s set up correctly. I assume Visual Studio is installed in the default location – adjust paths as necessary.

    Assume we are starting with the following directory structure:

    Project 
        Lib 
        Src
    

    Step 1: Copy Code Analysis Tooling

    Copy the entire contents of C:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop to Lib\Code Analysis.

    Copy the entire contents of C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\CodeAnalysis to Lib\Code Analysis.

    Copy the following files to Lib\Code Analysis:

    • C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualC\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualC.Dll
    • C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualStudio.CodeAnalysis.Sdk\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.CodeAnalysis.Sdk.dll
    • C:\Program Files\Microsoft Visual Studio 10.0\DIA SDK\bin\msdia100.dll
      C:\Program Files\Microsoft Visual Studio 10.0\VC\redist\x86\Microsoft.VC100.CRT\msvcp100.dll
    • C:\Program Files\Microsoft Visual Studio 10.0\VC\redist\x86\Microsoft.VC100.CRT\msvcr100.dll

    Step 2: Create Code Analysis Targets File

    Create a file called CodeAnalysis.targets and put it in your Src directory. Here is a starting point for the contents of this file. You should tweak as necessary for your needs:

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <PropertyGroup>
            <!--
            Inject our own target before the code analysis runs.
            -->
            <RunCodeAnalysisDependsOn>
                ConfigureCodeAnalysis;
                $(RunCodeAnalysisDependsOn);
            </RunCodeAnalysisDependsOn>
    
            <!--
            Ensure code analysis is run
            -->
            <RunCodeAnalysis>True</RunCodeAnalysis>
    
            <!--
            Set this to false if you don't want all code analysis violations to be treated as errors.
            -->
            <CodeAnalysisTreatWarningsAsErrors>True</CodeAnalysisTreatWarningsAsErrors>
            <!--
            This should be set to resolve to the Lib directory, which must contain the code analysis tooling.
            -->
            <PathToLib>$(MSBuildProjectDirectory)\..\..\Lib\</PathToLib>
            <!--
            This should be set to resolve to the directory containing this targets file.
            -->
            <PathToTargets>$(MSBuildProjectDirectory)\..\</PathToTargets>
    
            <!--
            Setting these properties is required in order for the code analysis targets to execute correctly.
            Without setting these, it will look for the tooling under default installation directories instead
            -->
            <CodeAnalysisTargets>$(PathToLib)\Code Analysis\Microsoft.CodeAnalysis.Targets</CodeAnalysisTargets>
            <CodeAnalysisPath>$(PathToLib)\Code Analysis</CodeAnalysisPath>
            <!--
            Assign default code analysis rules
            -->
            <CodeAnalysisRuleSet>$(PathToTargets)CodeAnalysis.Default.ruleset</CodeAnalysisRuleSet>
        </PropertyGroup>
        <UsingTask AssemblyFile="$(PathToLib)\MSBuildSdcTasks\Microsoft.Sdc.Tasks.dll" TaskName="StringComparison"/>
        <Target Name="ConfigureCodeAnalysis">
            <!--
            Assume that any projects with ".Tests" in their names are test projects
            -->
            <StringComparison Comparison="Contains" Param1="$(AssemblyName)" Param2=".Tests">
                <Output TaskParameter="Result" PropertyName="IsTestProject"/>
            </StringComparison>
            <!--
            Assign different rules for test projects (more relaxed)
            -->
            <CreateProperty Condition="$(IsTestProject)" Value="$(PathToTargets)CodeAnalysis.Tests.ruleset">
                <Output TaskParameter="Value" PropertyName="CodeAnalysisRuleSet"/>
            </CreateProperty>
        </Target>
    </Project>
    

    Step 3: Create Rule Sets

    Create files called CodeAnalysis.Default.ruleset and CodeAnalysis.Tests.ruleset in your Src directory. You can create these files with Visual Studio 2010 by choosing File / New / File / Code Analysis Rule Set. Alternatively, you can just copy the files from the example in the download.

    Step 4: Enable Code Analysis for Relevant Projects

    For every project that requires code analysis, open the .csproj file and insert the following before the import of Microsoft.CSharp.targets:

    <Import Project="..\CodeAnalysis.targets" />
    

    NOTE: it’s very important that this be inserted before the import of Microsoft.CSharp.targets, not after.

    Step 5: Tweak as Necessary

    You may wish to tweak the CodeAnalysis.targets, CodeAnalysis.Default.ruleset, and CodeAnalysis.Tests.ruleset files in order to alter the rules that are enabled, the conditions in which sets of rules are used, etc. As mentioned above, you can use VS2010 to create and edit .ruleset files.

    Code analysis is now integrated with your projects. Where you’re building from is irrelevant – whether it’s Visual Studio, the command line, or your build server. In all cases code analysis will execute for your project. You can download an example solution showing all this in action below.

    Troubleshooting

    If you get CA0001 Phx.FatalError, you likely need to register the msdia100.dll on the build machine:

    regsvr32 msdia100.dll
    

    You could possibly incorporate this into your build script, too, if your build user has sufficient rights.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.