Making NCover & NCover Explorer work on 64 bit machine

Background

In our project we have integrated code coverage feature into the automated build process. If the code is not covered to a minimum level using unit tests we fail the build on the continuous integration server. Recently we migrated to Windows 7 64 bit machine for our development machines. Similar to the continuous integration build we have a local build file which we run to ensure that everything works fine as expected before checking in the changes to the source repository. After moving to the 64 bit machine our local build started failing. Since our continuous integration server hosting Cruise Control.Net  was still 32 bit it was working fine.

Possible Reason for NCover & NCover Explorer not working

We are using the Test Driven.Net Visual Studio add-in which comes built in with the version of NCover and NCoverExplorer exe’s. From our MS Build file we invoke these two exe to calculate the code coverage and also to integrate the results as HTML output in the CCNet dashboard.

Although we install the TestDriven.Net add–in in the default location of program files for Visual Studio integration, for the purpose of automated build we copy all the dependent executables and third party dll’s like NUnit, Rhino mocks into a directory called Dependencies.

If we use the add-in and run the coverage from the Visual Studio IDE it works fine on 64 bit machine. But if we try to run the NCover exe from the command line it throws an error “Profiler process terminated. Profiler connection not established.”.

This could be because both NCover and NCover explorer are 32 bit exe. If we have to run them on the 64 bit operating system we need to explicitly force these exe’s to run under the x86 bit emulator under WOW64. We also use the NUnit-console exe to execute a set of unit tests. We also need to do the same for NUnit-console exe. But if we are using a NUnit version greater than 2.4.2 it comes with a separate exe named NUnit-Console-x86.exe which can be used on a 64 bit operating system.

Resolution

In order to force the NCover-Console exe to run in 64 bit emulation mode, we need to use the utility available in DotNet SDK called CorFlags.exe. Usually this exe is located at “C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin”.

Following is the syntax to use this utility

СorFlags.exe NCover.Console.exe /32BIT+

Please note that you’ll need to give the complete path to both the CorFlags.exe as well as NCover.Console.exe.

This step ensures that NCover.Console exe runs in 64 bit emulation mode. Even after doing this sometimes the build fails saying that NCover explorer exited with code –2. This is because we have set the property to fail the build if minimum coverage is not met. But ideally in a local build you would want to see the coverage report to see which parts of the code needs to be covered.

If you want to generate the HTML report even if the minimum coverage is not achieved, please set the ContinueOnError property of the NCover task in MS Build script as shown in below fragment

<NCover

    ToolPath="$(buildToolsDir)\NCover\"

    CommandLineExe="$(NUnitPath)\nunit-console-X86.exe"

    ContinueOnError ="true"

Also you can note that the CommandLineExe property points to the X86 version of the NUnit-console exe.

Conclusion

I wish that like NUnit even NCover comes up with a exe which can run in 64 bit emulator mode. Also it would be great if it can be inferred directly based on the command line itself whether to invoke the 32 bit or 64 bit version of the exe. Otherwise developers will need to change the build scripts to identify type of operating system and accordingly call the respective exe.

Hope this helps. Until next time happy programming :)

Share:
spacer

No comments:

Post a Comment