Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell nunit-console to use 4.0 under Mono?

Tags:

mono

c#-4.0

nunit

I set up a simple project under MonoDevelop, and can run the tests successfully (*) from there.

When I try nunit-console.exe from the commandline I get this:

 .../mono2/bin/Debug$ nunit-console mono2.exe
 NUnit version 2.5.10.0
 ...
 Runtime Environment - 
   OS Version: Unix 2.6.32.44
  CLR Version: 2.0.50727.1433 ( 2.10.8.1 (Debian 2.10.8.1-1~dhx1~lucid1) )

 ProcessModel: Default    DomainUsage: Single
 Execution Runtime: Default
 Unhandled Exception:
 System.ArgumentException: NUnit components for version 4.0.30319 of the CLR are not installed
 ...

If I've elided something important please let me know.

nunit-gui gave the same error. nunit-gui has an option to switch from 2.0 to 4.0, but when I try it gives me that same error again, and so doesn't let me change it.

More details: Ubuntu 10.04, using the http://badgerports.org/lucid.html repository, so Mono 2.10.8.1.

The project is set to use "Mono/.NET 4.0" according to Project Options in MonoDevelop.

MORE INFO:

/usr/bin/nunit-console contains this:

#!/bin/sh

exec /usr/bin/cli /usr/lib/nunit/nunit-console.exe "$@"

And the /usr/lib/nunit/ directory contains:

   3073 2011-03-14 18:13 nunit.exe.config
   2598 2011-03-14 18:13 nunit-console.exe.config
  23040 2012-02-29 10:19 nunit-console-runner.dll
   4608 2012-02-29 10:19 nunit-console.exe*
  76288 2012-02-29 10:19 nunit.uiexception.dll
 259072 2012-02-29 10:19 nunit.uikit.dll
 183808 2012-02-29 10:19 nunit-gui-runner.dll
   4096 2012-02-29 10:19 nunit.exe*

And nunit-console.exe.config contains:

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <runtime>
    <!-- We need this so test exceptions don't crash NUnit -->
    <legacyUnhandledExceptionPolicy enabled="1" />

    <!-- Look for addins in the addins directory for now -->
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="lib;addins"/>
   </assemblyBinding>

   <!--
    The following <assemblyBinding> section allows running nunit under 
    .NET 1.0 by redirecting assemblies. The appliesTo attribute
    causes the section to be ignored except under .NET 1.0
    on a machine with only the .NET version 1.0 runtime installed.
    If application and its tests were built for .NET 1.1 you will
    also need to redirect system assemblies in the test config file,
    which controls loading of the tests.
   -->
   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"
            appliesTo="v1.0.3705">

      <dependentAssembly> 
        <assemblyIdentity name="System" 
                          publicKeyToken="b77a5c561934e089" 
                          culture="neutral"/>
        <bindingRedirect  oldVersion="1.0.5000.0" 
                          newVersion="1.0.3300.0"/>
      </dependentAssembly>

      <dependentAssembly> 
        <assemblyIdentity name="System.Data" 
                          publicKeyToken="b77a5c561934e089" 
                          culture="neutral"/>
        <bindingRedirect  oldVersion="1.0.5000.0" 
                          newVersion="1.0.3300.0"/>
      </dependentAssembly>

      <dependentAssembly> 
        <assemblyIdentity name="System.Drawing" 
                          publicKeyToken="b03f5f7f11d50a3a" 
                          culture="neutral"/>
        <bindingRedirect  oldVersion="1.0.5000.0" 
                          newVersion="1.0.3300.0"/>
      </dependentAssembly>

      <dependentAssembly> 
        <assemblyIdentity name="System.Windows.Forms" 
                          publicKeyToken="b77a5c561934e089" 
                          culture="neutral"/>
        <bindingRedirect  oldVersion="1.0.5000.0" 
                          newVersion="1.0.3300.0"/>
      </dependentAssembly>

      <dependentAssembly> 
        <assemblyIdentity name="System.Xml" 
                          publicKeyToken="b77a5c561934e089" 
                          culture="neutral"/>
        <bindingRedirect  oldVersion="1.0.5000.0" 
                          newVersion="1.0.3300.0"/>
      </dependentAssembly>

    </assemblyBinding>

  </runtime>

</configuration>

*: Well, I have a problem when I try to use more exotic Nunit attributes; that is the real problem I am trying to troubleshoot which lead me to the one I describe above. However the exe being used above is the one with just two simple tests that do work fine in MonoDevelop.

like image 375
Darren Cook Avatar asked Jan 16 '23 05:01

Darren Cook


1 Answers

The trick is to modify the nunit-console, which (on Ubuntu 10.04, using badgerports, looks like /usr/bin/cli /usr/lib/nunit/nunit-console.exe), to tell /usr/bin/cli to use .NET 4!

So, when I do this command:

/usr/bin/cli --runtime=v4.0 /usr/lib/nunit/nunit-console.exe mytest.exe

I get this output:

NUnit version 2.5.10.0
...
Runtime Environment - 
   OS Version: Unix 2.6.32.44
  CLR Version: 4.0.30319.1 ( 2.10.8.1 (Debian 2.10.8.1-1~dhx1~lucid1) )

ProcessModel: Default    DomainUsage: Single
Execution Runtime: Default
..
Tests run: 2, Errors: 0, Failures: 0, Inconclusive: 0, Time: 0.040103 seconds
  Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0

If you are only ever going to use NET 4, you could edit /usr/bin/nunit-console to always set this.

(The real problem is /usr/bin/cli auto-detection is choosing NET 2 instead of NET 4; but after much searching I've found no way to control that auto-detection process.)


ASIDE: The reason I emphasized /usr/bin/cli, is that just telling nunit-console the framework to use fails (see below). I.e. The runtime version has to be given to /usr/bin/cli, not to nunit-console!

/usr/bin/cli /usr/lib/nunit/nunit-console.exe -framework=v4.0 mytest.exe
NUnit version 2.5.10.0
...
Runtime Environment - 
   OS Version: Unix 2.6.32.44
  CLR Version: 2.0.50727.1433 ( 2.10.8.1 (Debian 2.10.8.1-1~dhx1~lucid1) )

ProcessModel: Default    DomainUsage: Single
Execution Runtime: v4.0
Unhandled Exception:
System.ArgumentException: NUnit components for version 4.0 of the CLR are not installed
Parameter name: targetRuntime
  at NUnit.Util.TestAgency.LaunchAgentProcess (NUnit.Core.RuntimeFramework targetRuntime, Boolean enableDebug) [0x00000] in <filename unknown>:0 
...
like image 134
Darren Cook Avatar answered Jan 31 '23 03:01

Darren Cook