NAnt和双平台构建-在Windows和Mono / Linux上构建的最佳方法
我是NAnt的新手,但是对Ant和CruiseControl有一定的经验。
我想要做的是让我的SVN项目包含所有需要的工具(例如NUnit和Mocks等),以便我可以签到新机器并进行构建。 J.P Boodhoo在此概述了此策略。
到目前为止,如果我只想在Windows上运行,那就太好了,但是我也希望能够签到Linux并针对Mono进行构建/测试/运行。我不希望SVN项目外部存在任何依赖关系。我不介意项目中有两组工具,但只需要一个NAnt构建文件
这一定有可能,但是如何呢?诀窍/"年轻球员的陷阱"是什么
解决方案
回答
这不是一个特别困难的练习。我们在我的一个项目中做了一些相当相似的工作,因为其中一半使用Ant在Java上运行以运行相关目标,另一半是用于UI的.Net(C#)。项目在Windows计算机上运行以进行开发,但是服务器(Java)运行linux,但是在UAT环境(linux)中,我们需要运行nunits(集成测试)。这背后的真正技巧(不是很困难的技巧)是拥有一个可以在两种环境中运行的NAnt构建文件,这似乎与我们在此处尝试执行的操作相同。
当然我们意识到我们需要首先在Mono上安装NAnt:
$ 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\branches34\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 tortoise等)
有关Mono上Nunit等的更多帮助,请查看此精彩文章。
希望能有所帮助,
干杯,
罗布·G
回答
值得注意的是,像Nant这样的许多工具都是在开箱即用的单声道上运行的,即
mono nant.exe
作品
回答
@Rob G嘿!那是我的帖子! ;)
对于其他一些好的示例,请确保浏览NUnit源代码。我会尽可能与Charlie紧密合作,以确保它在Mono上进行构建和测试。他会尽可能地尝试跑步。