msbuildmononunitxbuild

Running a .net executable from an msbuild project in a platform independent way


I'm working on a .NET library, and I want the build script to be so generic that it can run from both the MS .NET framework, and from a mono installation on a Mac/Linux machine.

The problem here is running NUnit. I have downloaded the nunit executable and placed it in a lib folder. In order to execute it on my Mac, I have to write the following in my build script

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  ...

  <Target Name="Test" AfterTargets="Compile">
    <Exec Command="mono lib/NUnit/nunit-console.exe $(OutputAssembly)" />
  </Target>
</Project>

The thing is the "mono" part, which ties the build script to the mono framework. Is there a way I can write this build script so it will run on both on the MS .NET framework, and the Mono framework?

Now my problem here relates to NUnit. But it might as well be any other .NET executable.


Solution

  • You can use platform conditions, like this:

    <Exec Command="foo.exe arg1 arg2" Condition=" '$(OS)' == 'Windows_NT' " />
    

    to execute conditionally. The equivalent mono condition would be either "Unix" or "OSX" instead of "Windows_NT".

    For more information have a look here: http://www.mono-project.com/Porting_MSBuild_Projects_To_XBuild#Platform_specific_items