locked
How does VS 2010 and VS 2012 know which version of fxcopcmd.exe to use?

    Question

  • A developer on my team was evaluating VS 2012 with a project that performs code analysis.  He found that a greater number of fails occured against the same code using the same rule sets previously run in VS 2010.

    Question 1: did something change with the fxcop 11.x engine for VS 2012 that would account for this differenct?

    Question 2: When he returned to VS 2010 the code analysis performed seems to also now encounter bore fails.  He also believe VS 2010 is running the fxcop 11.x version and not the fxcop 10.x version as before.  What determines which version of fxcop is used from the VS 2010 IDE?

    Thanks

    -- Steven

    Friday, September 21, 2012 8:13 PM

Answers

  • Edit your project file and add a property to the propertygroup section:

    <CodeAnalysisPath>c:\program files\Microsoft Visual Studio 10\Team Tools\... ... ...\</CodeAnalysisPath>

    That should instruct msbuild to use the older FxCop. I haven't tried whether that also works in the IDE.


    My blog: blog.jessehouwing.nl

    Monday, September 24, 2012 8:35 PM

All replies

  • One more thing..

    We uninstalled .net 4.5 and then reinstalled .net 4.0 and now vs2010 code analysis is working as it did before vs2012/.net4.5 were installed.

    Does this mean that we can't install vs 2012/net 4.5 and continue to run the code analysis in VS2012 as we did before.

    Friday, September 21, 2012 9:41 PM
  • Code analysis in 2012 has been improved and will now find more and new issues and at the same time will trigger less frequently on false positives.

    Which fxcop version is triggered by msbuild is governed by the Micosoft.CodeAnalysis.targets file which is stored in your msbuild directory. You can override the directory msbuild will look for the fxcopcmd.exe from your project file or with a custom targets file or with a commandline parameter to fxcop.

    Though it's better to fix the new warnings. The are indicators of possible issues in your code. They just weren't found with the older FxCop. You could also do a mass suppress in global suppression file and look at these new issues when you change the code that contains these issues.


    My blog: blog.jessehouwing.nl

    Sunday, September 23, 2012 12:34 PM
  • Jesse,

    Thanks for your response.

    We do plan on fixing the new warnings as time permits.  But in the short term while we address this we would like to have VS2012 installed and configure the project to use the older fxcop. 

    Can you provide details on how to configure the project file to direct msbuild to use the older fxcopcmd from a VS2010 build.  I was not able to find information on doing this.

    Thanks.

    -- Steven

    Monday, September 24, 2012 8:18 PM
  • Edit your project file and add a property to the propertygroup section:

    <CodeAnalysisPath>c:\program files\Microsoft Visual Studio 10\Team Tools\... ... ...\</CodeAnalysisPath>

    That should instruct msbuild to use the older FxCop. I haven't tried whether that also works in the IDE.


    My blog: blog.jessehouwing.nl

    Monday, September 24, 2012 8:35 PM
  • Hi Jesse

    I have a similar wish to force the analysis engine to work the same way in VS 2010 no matter if VS 2012 is installed or not, because we currently only install VS 2012 on a few machines for test purposes.

    I have tried set the CodeAnalysisPath like you suggest above, but it does not seem to change the behavior. Actually it seems that it is running the VS2010 FxCopCmd.exe even if I am not setting the CodeAnalysisPath:

    Task "CodeAnalysis"
      Running Code Analysis...
      C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\FxCopCmd.exe  /outputCulture:1033 /out:"bin\Debug\MyAssembly.dll.CodeAnalysisLog.xml" /file:"bin\Debug\MyAssembly.dll" /dictionary:"MyDictionary.xml" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\PresentationCore.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\PresentationFramework.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.ComponentModel.Composition.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Xaml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\WindowsBase.dll"  /directory:"bin\Debug" /directory:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client" /ruleSet:"=My.ruleset" /rulesetdirectory:"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets" /rule:"-C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules" /searchgac /ignoreinvalidtargets /forceoutput /successfile /ignoregeneratedcode /saveMessagesToReport:Active /timeout:120
      Microsoft (R) FxCop Command-Line Tool, Version 10.0 (10.0.30319.1) X86

    Any help is appreciated!


    Tore Østergaard
    Oticon A/S, Denmark

    Thursday, November 29, 2012 9:38 AM
  • Visual Studio 2012 updates the Windows and .NET SDK for framework 4.0 to 4.5. So any changes this causes to the generated code/assemblies will result in changes in the FxCop rules that trigger.

    Comparing the generated code from WPF controls and Windows Workflow, I can see that the code generated differs in where the [GeneratedCode] attribute is applied, which will cause FxCop 10 (and 11 for that matter) to scan more code.

    I expect this only impacts .NET 4.0 and 4.5 projects, since the .NET Framework 4.5 is installed over the existing 4.0 Framework (just like 3.5 was an upgrade of 2.0).


    My blog: blog.jessehouwing.nl



    Thursday, November 29, 2012 11:27 AM
  • I wrote a blog post that links all posts and an open connect bug for this item.

    http://blog.jessehouwing.nl/2012/11/net-framework-sdk-45-changes-visual.html


    My blog: blog.jessehouwing.nl

    Thursday, November 29, 2012 12:25 PM