Setup NAnt
-
Create nant.bat
--------
@echo off
"D:\_Boyan's Documents\_Code Camp\nantAutomation\NAnt\bin\nant.exe" %*
-nologo
-
Copy to C:\Windows
Setup intellisense in Visual
Studio
-
Install the NAnt schema by copying the file "nant.xsd" form the NAnt\schema
distribution to "C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas" or
"C:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas" for Visual Studio
2008
-
Associate NAnt build files (.build) with the Visual Studio XML editor
-
Open any Visual Studio solution
-
Add a NAnt build file to it
-
Right click on the .build file and choose "Open With"
-
Select "XML Editor" and click on "Set as Default"
-
Add the "xmlns" (namespace) attribute to the "project" tag of your build
file. If you have copied the NAnt schema file (nant.xsd) to the right place,
adding the "xmlns" attribute should list the NAnt schema as one of the
available choices. The end result should look like:
<project name="displayMessage" default="run"
xmlns="http://nant.sf.net/release/0.85/nant.xsd">
-
Configure NAnt as an external tool
-
Go to Tools/External tools
-
Add a new tool:
-
Title: NAnt
-
Command: nant.bat
-
Arguments: /f:"$(ItemPath)"
-
Initial Directory: $(ProjectDir)
-
Check "Use Output Window"
-
Bind shortcut key through "Options/Keyboard/Tools.ExternalCommand1" =
Ctrl-Alt-N
Something More Useful
-
Define your project
<project name="testOS" default="runTest" basedir=".">
</project>
-
Add a property
<property name="operatingSystem" value=""
/>
-
Add the default target
<target name="runTest">
</target>
-
Use NAnt built in functions to get the name of the operating
system and save it inside the defined property
<property name="operatingSystem"
value="${operating-system::to-string(environment::get-operating-system())}"
/>
-
Test for the operating system name
<if test="${string::contains(operatingSystem, 'Microsoft
Windows NT 5.0')}">
<echo message="This is Windows 2000"
/>
</if>
<if test="${string::contains(operatingSystem, 'Microsoft
Windows NT 5.1')}">
<echo message="This is Windows XP"
/>
</if>
<if test="${string::contains(operatingSystem, 'Microsoft
Windows NT 5.2')}">
<echo message="This is Windows 2003"
/>
</if>
-
Save and execute
-
Complete build script
<project name="testOS" default="runTest" basedir=".">
<property name="operatingSystem"
value="${operating-system::to-string(environment::get-operating-system())}"
/>
<target name="runTest">
<if test="${string::contains(operatingSystem, 'Microsoft
Windows NT 5.0')}">
<echo message="This is Windows 2000" />
</if>
<if test="${string::contains(operatingSystem, 'Microsoft
Windows NT 5.1')}">
<echo message="This is Windows XP" />
</if>
<if test="${string::contains(operatingSystem, 'Microsoft
Windows NT 5.2')}">
<echo message="This is Windows 2003" />
</if>
</target>
</project>