开发者

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.


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


How about the following (tested) proposal:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <ManagedExeLauncher Condition="('$(OS)' != 'Windows_NT')">mono </ManagedExeLauncher>
     ...
  </PropertyGroup>      

  ...

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜