NAnt and MSBuild Tasks for NCover
I received an e-mail this week from Jay Flowers asking if I would be interested in helping him put together NCover and NCoverExplorer 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 and MSBuild 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.
Here is an example of the NAnt <ncover> task at it's simplest for NCover 1.3.3 -
[Update 03 Sep 2006: As of build 1.3.5.1789 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"
commandLineExe="Tools\NUnit\nunit-console.exe"
commandLineArgs="MyApp.UnitTests.dll"
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"
commandLineExe="Tools\NUnit\nunit-console.exe"
commandLineArgs="MyApp.UnitTests.dll /xml=MyApp.nunit.xml /labels /nologo"
workingDirectory="${build.output.dir}"
coverageFile="MyApp.ncover.xml"
logLevel="Verbose"
logFile="MyApp.ncover.log"
excludeAttributes="CoverageExcludeAttribute">
<assemblies basedir="${build.output.dir}">
<include name="MyApp*.dll" />
<exclude name="MyApp.UnitTests.dll" />
</assemblies>
</ncover>
Here is a simple MSBuild <NCover> task example:
<UsingTask TaskName="MSBuild.NCoverExplorer.Tasks.NCover"
AssemblyFile="MSBuild.NCoverExplorer.Tasks.dll" />
<NCover ToolPath="Tools\NCover\"
CommandLineExe="Tools\NUnit\nunit-console.exe"
CommandLineArgs="MyApp.UnitTests.dll" />
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 1.3.5.1789 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 1.3.5.1797 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 1.3.5.1861 now available. NOTE you must also upgrade your NCoverExplorer version to the latest 1.3.5 beta.]
Filed in: ncoverexplorer ncover nant msbuild
27 Comments:
Good stuff - thanks for the effort. I resorted to Exec in my MSBuild scripts, but would definitely have prefered a custom task such as this.
You should consider contributing these to NAntContrib and MSBuild Community Tasks respectively.
Awesome stuff. :) Agree with Kent, contribution to NAntContrib (and MSBuild Community) would be great.
If you want a hand let me know.
Kent/Matt, thanks for the feedback. I had wondered about NAntContrib and MSBuild Community when I wrote the "ncoverexplorer" tasks, however at the time I wanted the freedom to quickly enhance the API as I added new functionality. NAnt in particular had been pretty slow in its releases having a big hiatus at the time. Now that things are more stable and I have the "ncover" tasks too it may be more worth the effort. I will try to take a look into it when I get a chance to figure out who to contact etc...
Nice stuff kiwidude! Experienced a minor hitch and was wondering if you could help out. I wasn't able to make the NCover tasks work with multiple test assemblies and I thought that was possible.
I tried giving in the include clause a '*.dll' paramter, have even tried separating the two assemblies with a semi colon (as suggested by the ncover console) in the include clause and have tried multiple includes but still didnt work out.
Any ideas here?
Jasdeep - are you trying to use the NAnt task or the MSBuild one? The NAnt task assemblies node is just a "fileset" underneath. I find it useful to set the basedir on the assemblies node and then a wildcard pattern in the include node should work fine. Send me an e-mail if you are still having probs to 'support at ncoverexplorer dot org'.
Hello. I just sent an email at the address provided with the entire NANT build file.
Thanks for the help. Please let me know if you have any questions.
Re Jasdeep's issue - I believe this came down to not having the working directory set correctly. Set it to the folder where your assemblies you want to test/cover reside and all should work fine.
Just wanted to add my Nice work comment to the others - while I've had NAnt <exec>ing NCover before, I prefer to use custom tasks when possible.
I'm having one small problem though - while the unit tests run OK, the coverage.xml file doesn't get generated properly, there's just a stub file with no coverage results. Any thoughts?
Thanks for the kind words David. Most likely causes for your problem - you have not set the working directory correctly or you have not COM registered CoverLib.dll in the NCover folder. Add the "verbose=true" argument and e-mail me the NAnt output if still having problems - email address four comments above.
Hi, thanks for your great work !. I followed all your directions, put the custom task into the Nant bin folder but I still recieve teh folowing error:
Invalid element trycatch
Vikash - if your nant script makes use of the trycatch task then you need to be sure you have "nantcontrib" installed. If you or anyone else has further queries on these tasks please instead post them in the forums over at http://ncover.org/site/forums/
Perhaps, isn't it a typing error?
at NAnt ncover task for NCover 1.5.*
coverageExclusions="CoverageExcludeAttribute" --> excludeAttributes="CoverageExcludeAttribute"
Thanks for the spot tsune, fixed.
Don't worry, I eventually found out what the problem was - the version I was using did not support multiple assemblies. I downloaded the v1.3.4.1736 version, and that works just fine.
Is there a changelog published somewhere? That might save another morning or two of head-scratching!
I must say, that after getting NAnt/NUnit/NCover/NCoverExplorer all up and running with CruiseControl.NET, I look like an absolute f***ing hero in my department. The beautiful code coverage reports appearing in CC.NET are the cherry on top :-)
Hey David, glad to hear you got there in the end and you are pleased with the result! As far as the changelog goes - I admit it is an omission from the zip compared to what I do for the NCoverExplorer release notes. I have just now pushed up a new version of this post with links to yet another update of the tasks - all changes are mentioned in the NCoverExplorer 1.3.5 beta forum thread referenced in there.
Hi kiwidude, I used a previous version of ncover NAnt task without any problem.
With the new one (1789), I get an issue with the "commandLineArgs" parameter.
I used it to pass to NUnit several test assemblies separated by spaces and this worked well, this doesn't work anymore.
FYI, it works with a single test assembly.
Romu,
Can you please post your query in the NCover forums (or email me) instead of here? If you can show your xml ncover task I can take a look. Also you could try the NCoverExplorer 1.3.5 beta which generates nant/msbuild tasks etc to check against your own syntax. Thanks.
Ok, I'm goiing to post now
Can some one help me with a ccnet.config file which uses MSBuild to build and NCover to find coverage using Cruisecontrol.NET ?
Would appreciate if you can send the config file it to my account rgovardh@gmail.com.
Thanks a ton
-Rama
Thanks a bunch brother. This was the most straightforward explanation. Implementation, integration with Nant and CC.net was simplistic.
Cheers
Great blog!
We have one problem though. We're using NCover 2.1 with MSBuild and MSTest. We get a coverage file, but although it contains data, it appears to be missing the visitcount attribute on all the seqpnt elements, and therefore the XSL generates no output. This is puzzling, since when we view the build log of the project through CruiseControl, it states "Sequence Point Coverage: 40.0%" and "Branch Coverage: 40.3%". Do you have any ideas that might help us resolve this problem?
Hi Rory,
Any problems related to 2.x I suggest you post on the forums at www.ncover.com where I know the guys will be more than happy to help you out.
Nice hard work, really appreciated! Can anyone help me to Config ccnet.config file for my firstproject with Cruise control, everything work well so far , as i can force the build but now i want to run my unit test with Nunit, how to configure them with Cruise control. Any kind of help/direction will be appreciated.
nlohchab@gmail.com
I have a problem running Nant Script. I get coverage file but it doesn't have any data. So the html output say 0% coverage. I am using NCover 1.5.8
us - I suggest you either take a look at my blog posts on "NCover Problems / Fixes" and if that doesn't fix it for you then post to the "legacy" version forums at ncover.com.
Links be busted :(
The Downloads link on the RHS wasn't - or I would also suggest going to NCover.com which supports bot the free and commercial versions. This is a very old post dude!
Post a Comment
<< Home