Quantcast
Viewing all articles
Browse latest Browse all 10

Adding FxCop to a “FAKE” build script

In the last article I showed how we can use “FAKE – F# Make” to set up a build script which

  1. Cleans up old build outputs
  2. Compiles our main projects
  3. Compiles test projects
  4. Uses NUnit to test our assembly
  5. Zips the assemblies to a deploy folder.

This time we will improve the same Calculator sample (download here) with a task for FxCop, so please make sure you succeeded with the last article.

“FxCop is a free static code analysis tool from Microsoft that checks .NET managed code assemblies for conformance to Microsoft’s .NET Framework Design Guidelines.”

[Wikipedia]

Setting up FxCop

Open build.fsx from your Calculator sample folder and add a new target “FxCop” to the targets section:

In the dependencies section modify the build order to:

That’s it. If you run your build script you will get new *.xml file in the .\test\-folder:

Image may be NSFW.
Clik here to view.
image

There are a lot of parameters for the FxCop task. Some are described on the project page.

Letting the build fail

If you were using MSBuild before you might know how hard it is to let MSBuild fail your build if FxCop reports any errors or warnings.

With FAKE the only thing you have to do is setting the “FailOnError” parameter:

Image may be NSFW.
Clik here to view.
image

If you activate this option FxCop errors will cause your build to fail. Possible values are:

  • FxCopErrorLevel.Warning
  • FxCopErrorLevel.CriticalWarning
  • FxCopErrorLevel.Error
  • FxCopErrorLevel.CriticalError
  • FxCopErrorLevel.ToolError
  • FxCopErrorLevel.DontFailBuild

The values are cummulative. If you choose FxCopErrorLevel.CriticalWarning the build will fail for critical warnings, errors, critical errors and FxCop tool errors but not for simple warnings. The default is FxCopErrorLevel.DontFailBuild.

Original article: Adding FxCop to a “FAKE” build script

©2013 Rash thoughts about .NET, C#, F# and Dynamics NAV.. All Rights Reserved.


Viewing all articles
Browse latest Browse all 10

Trending Articles