I received an e-mail this week from Jay Flowers
asking if I would be interested in helping him put together NCover
plugins for CI Factory
. The intent is to provide these as an alternative for the CoverageEye
package he already includes.
I normally use the NAnt <exec>
task for running NCover on our build servers, which does the job fine once you have it setup. There is unfortunately a bit of pain involved in truly dynamic scripts ensuring paths with spaces are handled correctly, building delimited lists of assemblies etc. The NCover command line in combination with NUnit can be a frustrating learning curve, not to mention it has changed between versions so even looking for answers in web blog articles can be confusing when they are out of date or "simplified".
To make this a little more painless for both Jay and anyone else interested I ended up creating NAnt
tasks for NCover, supporting NCover 1.3.3 and 1.5.x to date.
I have now included these tasks in my existing NCoverExplorer NAnt/MSBuild task assemblies located in NCoverExplorer.Extras.zip
, along with all the source code and example .build/.proj files.
Note: These tasks still require that NCover has it's CoverLib.dll COM registered correctly on your machine. You can always do this as part of your NAnt/MSBuild script prior to using these tasks if not using the default NCover MSI installation.
Here is an example of the NAnt <ncover>
task at it's simplest for NCover 1.3.3 -
note the use of the version attribute. The <ncover> task will default to NCover 1.5.4 command line syntax if this is not present.[Update 03 Sep 2006: As of build 22.214.171.1249 the <ncover> tasks are self registering without needing local admin rights. The version attribute is also now redundant - it will be picked up from the NCover.Console.exe assembly if not specified]<ncover program="Tools\NCover\NCover.Console.exe"
A more complex NAnt example using NCover 1.5.4 showing additional NUnit arguments, customised logging and xml filenames, a coverage exclusion attribute (in the root namespace) and specific non-test assemblies to report coverage on:<ncover program="Tools\NCover\NCover.Console.exe"
commandLineArgs="MyApp.UnitTests.dll /xml=MyApp.nunit.xml /labels /nologo"
<include name="MyApp*.dll" />
<exclude name="MyApp.UnitTests.dll" />
Here is a simple MSBuild <NCover>
task example:<UsingTask TaskName="MSBuild.NCoverExplorer.Tasks.NCover"
I did manage to confirm a few bugs/unfinished features in NCover 1.5.4 itself while giving this a test, so where possible I have either worked around or excluded these features until they are one day resolved. FYI, they involved the //q and //h command line arguments, which you should avoid using!
Feel free to leave a comment or drop me an e-mail if you find these tasks useful (or find a bug of course!).Download NCoverExplorer.Extras.zip (CC.Net/NAnt/MSBuild)[Update: I'm more than happy to answer questions for people adding these into their builds. However rather than using the blog comments can you please put your query in the NCover or NCoverExplorer forums as I blogged about here.][Update 03 Sep 2006: NAnt and MSBuild tasks have been updated and improved. See this thread for the changes listed in build 126.96.36.1999 or the 1.3.5 release notes. Documentation can now be found here for MSBuild and here for NAnt (or in the zip file).][Update 07 Sep 2006: Bug-fix update for the NCover tasks where multiple arguments specified in the command line. Build 188.8.131.527 now available at the above links.][Update 01 Oct 2006: Updates to the NCoverExplorer tasks to support a new regular expression feature for coverage exclusions and improved documentation. Build 184.108.40.2061 now available. NOTE you must also upgrade your NCoverExplorer version to the latest 1.3.5 beta.]