<p>I'm new to NAnt but have some experience with Ant and CruiseControl.</p>

<p>What I want to do is have my SVN project include all tools needed (like NUnit and Mocks etc) so I can check out onto a fresh machine and build. This strategy is outlined by J.P Boodhoo <a href="http://blog.jpboodhoo.com/NAntStarterSeries.aspx" rel="noreferrer">here.</a></p>

<p>So far so good if I only want to run on Windows, but I want to be able to check out onto Linux and build/test/run against Mono too. I want no dependencies external to the SVN project. I don't mind having two sets of tools in the project but want only one NAnt build file</p>

<p>This must be possible - but how? what are the tricks / 'traps for young players' </p>

[{'answer_id': 32317, 'author': 'RobertTheGrey', 'author_id': 1107, 'author_profile': 'https://Stackoverflow.com/users/1107', 'pm_score': 4, 'selected': True, 'text': '<p>This shouldn\'t be a particularly difficult excercise. We do some fairly similar stuff on one of my projects since half of it runs on Java using Ant to run relevant targets, and the other half is .Net (C#) for the UI. The projects get run on windows machines for development, but the servers (Java) run linux, but in the UAT environment (linux) we need to run the nunits (integration tests). The real trick (not really a difficult trick) behind this is having a NAnt build file that can run in both environments which seems to be the same thing you\'re trying to do here.</p>\n\n<p>Of course you realise you\'ll need to install NAnt on Mono first:</p>\n\n<pre><code>$ export MONO_NO_UNLOAD=1\n$ make clean\n$ make\n$ mono bin/NAnt.exe clean build\n</code></pre>\n\n<p>And then your build file needs to be written in such a way that it seperates concerns. Some parts of the build file written for windows will not work in linux for example. So you really just need to divide it up ito specific targets in the build file. After that, there are a number of ways you can run a specific targets from the command line. An example might look like this:</p>\n\n<pre><code>&lt;project name="DualBuild"&gt;\n  &lt;property name="windowsDotNetPath" value="C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5" /&gt;\n  &lt;property name="windowsSolutionPath" value="D:\\WorkingDirectory\\branches\\1234\\source" /&gt;\n  &lt;property name="windowsNUnitPath" value="C:\\Program Files\\NUnit-Net-2.0 2.2.8\\bin" /&gt;\n  &lt;property name="monoPath" value="You get the idea..." /&gt;\n\n  &lt;target name="BuildAndTestOnWindows" depends="WinUpdateRevision, WinBuild, WinTest" /&gt;\n  &lt;target name="BuildAndTestOnLinux" depends="MonoUpdateRevision, MonoBuild, MonoTest" /&gt;\n\n  &lt;target name="WinUpdateRevision"&gt;\n    &lt;delete file="${windowsSolutionPath}\\Properties\\AssemblyInfo.cs" /&gt;\n    &lt;exec program="subwcrev.exe" basedir="C:\\Program Files\\TortoiseSVN\\bin\\"\n          workingdir="${windowsSolutionPath}\\Properties"\n          commandline="${windowsSolutionPath} .\\AssemblyInfoTemplate.cs\n                       .\\AssemblyInfo.cs" /&gt;\n    &lt;delete file="${windowsSolutionPath}\\Properties\\AssemblyInfo.cs" /&gt;\n    &lt;exec program="subwcrev.exe" basedir="C:\\Program Files\\TortoiseSVN\\bin\\"\n          workingdir="${windowsSolutionPath}\\Properties"\n          commandline="${windowsSolutionPath} .\\AssemblyInfoTemplate.cs \n                       .\\AssemblyInfo.cs" /&gt;\n  &lt;/target&gt;\n\n  &lt;target name="WinBuild"&gt;\n    &lt;exec program="msbuild.exe"\n          basedir="${windowsDotNetPath}"\n          workingdir="${windowsSolutionPath}"\n          commandline="MySolution.sln /logger:ThoughtWorks.CruiseControl.MsBuild.XmlLogger,\n                       ThoughtWorks.CruiseControl.MsBuild.dll;msbuild-output.xml \n                       /nologo /verbosity:normal /noconsolelogger \n                       /p:Configuration=Debug /target:Rebuild" /&gt;\n  &lt;/target&gt;\n\n  &lt;target name="WinTest"&gt;\n    &lt;exec program="NCover.Console.exe"\n          basedir="C:\\Program Files\\NCover"\n          workingdir="${windowsSolutionPath}"&gt;\n      &lt;arg value="//x &amp;quot;ClientCoverage.xml&amp;quot;" /&gt;\n      &lt;arg value="&amp;quot;C:\\Program Files\\NUnit-Net-2.0 2.2.8\\bin\n                       \\nunit-console.exe&amp;quot; \n                       MySolution.nunit /xml=nunit-output.xml /nologo" /&gt;\n    &lt;/exec&gt;\n  &lt;/target&gt;\n\n  &lt;target name="MonoUpdateRevision"&gt;\n    You get the idea...\n  &lt;/target&gt;\n\n\n  &lt;target name="MonoBuild"&gt;\n    You get the idea...\n  &lt;/target&gt;\n\n  &lt;target name="MonoTest"&gt;\n    You get the idea...\n  &lt;/target&gt;\n\n&lt;/project&gt;\n</code></pre>\n\n<p>For brevity, I\'ve left both sides out. The neat thing is you can use NUnit as well as NAnt on both environments and that makes things really easy from a dependency point of view. And for each executable you can swap out for others that work in that environment, for example (xBuild for MSBuild, and svn for tortoise etc)</p>\n\n<p>For more help on Nunit etc on Mono, check out <a href="http://blog.coryfoy.com/2006/02/nunitnant-and-mono-on-linux/" rel="nofollow noreferrer">this fantastic post</a>.</p>\n\n<p>Hope that helps,</p>\n\n<p>Cheers,</p>\n\n<p>Rob G</p>\n'}, {'answer_id': 46075, 'author': 'Frep D-Oronge', 'author_id': 3024, 'author_profile': 'https://Stackoverflow.com/users/3024', 'pm_score': 1, 'selected': False, 'text': "<p>It is worth noting that a lot of tools like Nant run on mono 'out of the box', i.e.</p>\n\n<pre><code>mono nant.exe\n</code></pre>\n\n<p>works</p>\n"}, {'answer_id': 46099, 'author': 'Cory Foy', 'author_id': 4083, 'author_profile': 'https://Stackoverflow.com/users/4083', 'pm_score': 2, 'selected': False, 'text': "<p>@Rob G - Hey! That's my post! ;)</p>\n\n<p>For some other good examples, be sure to browse the NUnit source code. I work closely with Charlie whenever I can to make sure it is building and testing on Mono. He tries to run whenever he can as well. </p>\n"}, {'answer_id': 34782467, 'author': 'Mark Bowker', 'author_id': 4528082, 'author_profile': 'https://Stackoverflow.com/users/4528082', 'pm_score': 0, 'selected': False, 'text': '<p>I use the following template. It allows simple building on any platform (<code>build</code> on Win or <code>./build.sh</code> on linux) and minimises duplication in the build scripts.</p>\n\n<hr>\n\n<p>The NAnt executable is stored with the project in <code>tools\\nant</code>.</p>\n\n<p>The build config file determines which build tool to use, either MSBuild or xbuild (in this case, for Windows I require the VS2015 MSBuild version, change the path as required).</p>\n\n<p>The <code>build-csproj</code> build target can be reused for when you have multiple projects within a solution.</p>\n\n<p>The <code>test-project</code> target would need to be expanded upon for your needs.</p>\n\n<p><strong>build.bat</strong></p>\n\n<pre><code>@tools\\nant\\nant.exe %*\n</code></pre>\n\n<p><strong>build.sh</strong></p>\n\n<pre><code>#!/bin/sh\n\n/usr/bin/cli tools/nant/NAnt.exe "$@"\n</code></pre>\n\n<p><strong>default.build</strong></p>\n\n<pre><code>&lt;?xml version="1.0"?&gt;\n&lt;project name="MyProject" default="all"&gt;\n\n  &lt;if test="${not property::exists(\'configuration\')}"&gt;\n    &lt;property name="configuration" value="release" readonly="true" /&gt;\n  &lt;/if&gt;\n\n  &lt;if test="${platform::is-windows()}"&gt;\n    &lt;property name="BuildTool" value="C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\MSBuild.exe" readonly="true"/&gt;\n  &lt;/if&gt;\n  &lt;if test="${platform::is-unix()}"&gt;\n    &lt;property name="BuildTool" value="xbuild" readonly="true"/&gt;\n  &lt;/if&gt;\n\n  &lt;property name="TestTool" value="tools/mytesttool.exe"/&gt;\n\n  &lt;target name="all" depends="myproject myprojectlib" /&gt;\n\n  &lt;target name="build-csproj" description="Build a given csproj"&gt;\n    &lt;!-- Must not be called standalone as it requires some properties set. --&gt;\n    &lt;exec program="${BuildTool}"&gt;\n      &lt;arg path="src/${ProjectName}/${ProjectName}.csproj" /&gt;\n      &lt;arg line="/property:Configuration=${configuration}" /&gt;\n      &lt;arg value="/target:Rebuild" /&gt;\n      &lt;arg value="/verbosity:normal" /&gt;\n      &lt;arg value="/nologo" /&gt;\n    &lt;/exec&gt;\n  &lt;/target&gt;\n\n  &lt;target name="test-project"&gt;\n    &lt;!-- Must not be called standalone as it requires some properties set. --&gt;\n    &lt;exec program="${TestTool}"&gt;\n      &lt;arg path="my/${ProjectName}/tests/path/for/tool" /&gt;\n      &lt;arg value="/aproperty=value" /&gt;\n    &lt;/exec&gt;\n  &lt;/target&gt;\n\n  &lt;target name="myproject" description="Build the project"&gt;\n    &lt;property name="ProjectName" value="MyProject"/&gt;\n    &lt;call target="build-csproj" /&gt;\n    &lt;call target="test-project" /&gt;\n  &lt;/target&gt;\n\n  &lt;target name="myprojectlib" description="Build the project\'s library dll"&gt;\n    &lt;property name="ProjectName" value="MyProjectLib"/&gt;\n    &lt;call target="build-csproj" /&gt;\n    &lt;call target="test-project" /&gt;\n  &lt;/target&gt;\n\n&lt;/project&gt;\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/32027', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3024/']