This is not the prettiest solution - but is the only way I could easily get it all working - so I could click the Run button from VS to startup NUnit and run my tests project.
As a primer, read James Newkirks article on this (he explains the config files a bit more than I do).
Firstly to get NUnit to work with .NET 2.0 assemblies you need to have this in your nunit config file (nunit-gui.exe.config):
<startup>
<supportedRuntime version="v2.0.50727" />
<requiredRuntime version="v2.0.50727" />
</startup>
If you include a line referencing v1.1 then it'll use 1.1.
So this means to run both 2.0 and 1.1 we need 2 config files.
The 1.1 config file has this startup section:
<startup>
<supportedRuntime version="v1.1.4322" />
</startup>
Unfortuntely I couldnt see any obvious way to tell NUnit to point to a specific config file (there is /config option but I believe that is for configurations within NUnit - not which app config file to use). So to get around this there are 2 options:
- Use 2 config files and use a batch script to rename the appropriate one to nunit-gui.exe.config prior to starting Nunit.
- Use 2 config files and 2 executable files (named to match the config files).
I chose 2. because it removes any ambiguitiy. So what I have are the following files in the Nunit bin dir:
- nunit-gui_1.1.exe
- nunit-gui_1.1.exe.config
- nunit-gui_2.0.exe
- nunit-gui_2.0.exe.config
Running the exe's will start NUnit with the corresponding .NET runtime version.
Now to get it working from VS was the next problem...
For some reason starting NUnit for 2.0 from VS2005 does not work.
The workaround (dont have time to figure out the real cause) is to create a 1.1 console app that executes another program - like a batch script (I tried a batch script but that had complications too). Here's the code:
public static void Main(string[] args)
{
if(args.Length==0)
{
Console.WriteLine("Error: No command specified.");
Console.WriteLine("Syntax: CmdRunner.exe [ ...]");
Console.WriteLine("Note must be the full path to the executable. Parameters are optional.");
return;
}
string paramsToPass = "";
for(int i=1;i {
if(paramsToPass!="")
paramsToPass+=",";
paramsToPass += args[i];
}
Console.WriteLine("About to run: " + args[0]);
Console.WriteLine("Passing params: " + (paramsToPass==""?"":paramsToPass));
try
{
System.Diagnostics.Process.Start(args[0], paramsToPass);
}
catch(Exception ex)
{
Console.WriteLine("Error occured trying to run: " + args[0]);
Console.WriteLine("Exception: " + ex.Message);
}
}
I called this CmdRunner.exe.
Next problem was that this didnt like spaces in the parameters passed to it (these were in my project directory structure). So modify your path to use the old 8.3 notation (to find out what this is do a "dir /x" at the command prompt).
Lastly, setup VS to run this when you click on Run:
VS.NET 2003:
- Under project properties select Debug.
- Set Debug Mode to Program
- Set Start Application to the CmdRunner path eg: O:\Visual Studio Projects\CmdRunner\bin\Debug\CmdRunner.exe
- Set Command Line Arguments to the appropriate NUnit version plus the assembly dll. It is critical that these contain no spaces. Also, if you want NUnit to automatically run the tests upon startup, then the /run argument needs to be included in the second argument string (this has one space before it). Note these must be enclosed in quotes eg:
"C:\Progra~1\NUNIT2~1.2\bin\nunit-gui_1.1.exe" "C:\Dev\VSSWRK\Ecommerce\DotnetVarious\DRKW~1.DIR\Tests\bin\Debug\Tests.dll /run"
VS2005:
- Under project properties select Debugging tab.
- Set Start Action to 'Start external program' and set it's path to the CmdRunner path. Because this 1.1 program is CLR compatible with 2.0 there's no problems running it from here) eg: O:\Visual Studio Projects\CmdRunner\bin\Debug\CmdRunner.exe
- Set Command Line Arguments to the appropriate NUnit version plus the assembly dll. It is critical that these contain no spaces. Also, if you want NUnit to automatically run the tests upon startup, then the /run argument needs to be included in the second argument string (this has one space before it). Note these must be enclosed in quotes eg:
"C:\Progra~1\NUNIT2~1.2\bin\nunit-gui_2.0.exe" "C:\Dev\VSSWRK\Ecommerce\DotnetVarious\DRKWDI~1.1\Net2.0Tests\bin\Debug\Net2.0Tests.dll /run"
And that's it. Good luck.
HTH
Tim