Tuesday, December 7, 2010

Make NCover work on 64-bit machine

It seems that the free NCover does not work well on 64-bit machine. One solution is to force your testing targets and ncover binaries to run as 32-bit mode, even they are managed binaries compiled with AnyCPU configuration.

The steps are as below:

1: change the PE flag in NCover.Console.exe:
corflags ncover.console.exe /32bit+
corflags is available in visual studio's command prompt

2: create a config file as below

   1: <?xml version="1.0" encoding="utf-8"?>
   2: <ProfilerSettings>
   3:   <!-- The unit-test loading program, should also be 32-bit, either change pe flag or rename to another one: nunit-console-x86.exe -->
   4:   <CommandLineExe>C:\Program Files (x86)\NUnit 2.5.5\bin\net-2.0\nunit-console.exe</CommandLineExe>
   5:   <CommandLineArgs>Test.dll</CommandLineArgs>
   6:   <!-- The target assembly to be loaded -->
   7:   <WorkingDirectory>D:\Test\bin\Release</WorkingDirectory> working folder
   8:   <CoverageXml>coverage.xml</CoverageXml>
   9:   <XmlFormat>Xml1</XmlFormat>
  10:   <LogFile>coverage.log</LogFile>
  11:   <VerboseLog>false</VerboseLog>
  12:   <NoLog>false</NoLog>
  13:   <ProfileIIS>false</ProfileIIS>
  14:   <DumpOnErrorNormal>false</DumpOnErrorNormal>
  15:   <DumpOnErrorFull>false</DumpOnErrorFull>
  16:   <CoverageBinary>Coverage.bcv</CoverageBinary>
  17:   <AutoExclude>true</AutoExclude>
  18: </ProfilerSettings>
  19:  
3: run below command to use ncover
"C:\Program Files (x86)\NCover\NCover.Console.exe" //r "D:\yourTesting.dll.ncoversettings"


4: after unittest is done, you can find a output file "coverage.xml" under the working folder set as above, then import into ncoverexplorer.exe

Although the configuration file can also be loaded and run from ncoverexplorer.exe, but seems to have some performance problem. So, I still prefer to run it from command line.

1 comment:

  1. If you still get this error message after the steps above then try to use the //reg option when running NCover

    ReplyDelete