moodmosaic (Nikos Baxevanis)
Blog - About - Open Source - Bookmarks - Tags

How to enable Code Analysis for F# projects

Sunday, 08 September 2013

As of today, in Visual Studio 2012 the Run Code Analysis command is not available for F# projects.

Code Analysis is a Visual Studio feature for analyzing managed code assemblies and gathering information such as possible design, localization, performance, and security improvements.

Code Analysis can be used as a stand-alone tool with the FxCopCmd command-line application and it is also possible to be included to automated build processes such is MSBuild.

Enable Code Analysis in MSBuild

To enable Code Analysis in MSBuild, include the following elements in the project file:



Unfortunately, even with the above elements, Code Analysis will not run for F# projects during the MSBuild process.


Edit the Microsoft.CodeAnalysis.Targets file which is located at: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\CodeAnalysis

Append or '$(Language)'=='F#' at the following locations:

<DefineConstants Condition="'$(Language)'=='C#' ">CODE_ANALYSIS;$(DefineConstants)</DefineConstants>
<PropertyGroup Condition="'$(Language)'=='C#' or '$(Language)'=='VB'">

You may also download the modified Microsoft.CodeAnalysis.Targets file from here.


This post has been filed under #f#


Have feedback on this page? Let @nikosbaxevanis know on twitter. Need help or found a bug? Contact me.

© 2011-2018 Nikos Baxevanis. All written content on this site is provided under a Creative Commons ShareAlike license. All code is provided under a MIT license unless otherwise stated.