这不应该是一个特别困难的练习。在我的一个项目中,我们做了一些相当类似的工作,因为它的一半运行在使用Ant的Java上运行相关目标,另一半则是用于UI的.Net(C#)。这些项目运行在Windows机器上进行开发,但服务器(Java)运行linux,但在UAT环境(linux)中,我们需要运行nunits(集成测试)。真正的技巧(不是一个很难的技巧)背后有一个NAnt构建文件,可以在这两种环境中运行,这似乎是你在这里尝试做的同样的事情。
当然你意识到你需要先在Mono安装楠:
$ export MONO_NO_UNLOAD=1
$ make clean
$ make
$ mono bin/NAnt.exe clean build
然后生成文件需要在它的方式隔开关注这样的方式来写。例如,为Windows编写的构建文件的某些部分在Linux中不起作用。所以你真的只需要在构建文件中将它分成特定的目标。之后,您可以通过多种方式从命令行运行特定的目标。一个例子可能是这样的:
<project name="DualBuild">
<property name="windowsDotNetPath" value="C:\WINDOWS\Microsoft.NET\Framework\v3.5" />
<property name="windowsSolutionPath" value="D:\WorkingDirectory\branches\1234\source" />
<property name="windowsNUnitPath" value="C:\Program Files\NUnit-Net-2.0 2.2.8\bin" />
<property name="monoPath" value="You get the idea..." />
<target name="BuildAndTestOnWindows" depends="WinUpdateRevision, WinBuild, WinTest" />
<target name="BuildAndTestOnLinux" depends="MonoUpdateRevision, MonoBuild, MonoTest" />
<target name="WinUpdateRevision">
<delete file="${windowsSolutionPath}\Properties\AssemblyInfo.cs" />
<exec program="subwcrev.exe" basedir="C:\Program Files\TortoiseSVN\bin\"
workingdir="${windowsSolutionPath}\Properties"
commandline="${windowsSolutionPath} .\AssemblyInfoTemplate.cs
.\AssemblyInfo.cs" />
<delete file="${windowsSolutionPath}\Properties\AssemblyInfo.cs" />
<exec program="subwcrev.exe" basedir="C:\Program Files\TortoiseSVN\bin\"
workingdir="${windowsSolutionPath}\Properties"
commandline="${windowsSolutionPath} .\AssemblyInfoTemplate.cs
.\AssemblyInfo.cs" />
</target>
<target name="WinBuild">
<exec program="msbuild.exe"
basedir="${windowsDotNetPath}"
workingdir="${windowsSolutionPath}"
commandline="MySolution.sln /logger:ThoughtWorks.CruiseControl.MsBuild.XmlLogger,
ThoughtWorks.CruiseControl.MsBuild.dll;msbuild-output.xml
/nologo /verbosity:normal /noconsolelogger
/p:Configuration=Debug /target:Rebuild" />
</target>
<target name="WinTest">
<exec program="NCover.Console.exe"
basedir="C:\Program Files\NCover"
workingdir="${windowsSolutionPath}">
<arg value="//x "ClientCoverage.xml"" />
<arg value=""C:\Program Files\NUnit-Net-2.0 2.2.8\bin
\nunit-console.exe"
MySolution.nunit /xml=nunit-output.xml /nologo" />
</exec>
</target>
<target name="MonoUpdateRevision">
You get the idea...
</target>
<target name="MonoBuild">
You get the idea...
</target>
<target name="MonoTest">
You get the idea...
</target>
</project>
为简洁起见,我已将双方都抛在了一边。整洁的事情是,你可以在两种环境中使用NUnit和NAnt,并且从依赖的角度来看,这使事情变得非常简单。并且对于每个可执行文件,你可以换出在其他环境中工作的其他人,例如(xBuild for MSBuild,svn for tool等)
欲了解Mono上Nunit等的更多帮助,请查看this fantastic post。
希望帮助,
干杯,
罗布摹