views:

1016

answers:

3

I am just getting started using NAnt. I was working from a tutorial, and just trying to set a target to clean my solution on build. My Visual Studio Solution structure is as follows:

  • Solution Folder
    • Project Folder
    • Project Folder
    • Tools Folder
      • NAnt Folder

The NAnt .exe file resides in the Tools/NAnt folder. My .build file is also in there. Here is my .build file:

<?xml version="1.0" encoding="utf-8" ?>
<project name="NAntTest" default="build" xmlns="http://nant.sf.net/release/0.86-beta1/nant.xsd"&gt;
  <property name="solution.file.name" value="NAntTest.sln" />
  <property name="project.config" value="debug" />

  <target name="build" depends="clean.source" />

  <target name="clean.source">
    <exec program="${framework::get-framework-directory(framework::get-target-framework())}\msbuild.exe"
          commandline="${solution.file.name} /t:Clean /p:Configuration=${project.config} /v:q" 
          workingdir="."/>
  </target>

</project>

This is how the example I am following was formatted. If I try to run this build, I get an error stating that the project file does not exist. In the clean.source target, if I replace the workingdir attribute with a hard coded path to my base solution folder, the script compiles and runs correctly. Obviously, this is not ideal for portability if I need to move the project anywhere.

How do I get NAnt to see the base working directory?

A: 

You could try setting the basedir attribute of the project node. This may resolve your problem.

<project name="NAntTest" default="build" basedir="C:\Code\MyProject" xmlns="http://nant.sf.net/release/0.86-beta1/nant.xsd"&gt;
Henryk
+2  A: 

My recommendation is to always place the build file at solution level. Then all relative paths in the build file will be equal to that of the solution.

Peter Lillevold
Moving this up into the solution directory worked. Thanks for the help!
Mark Struzinski
+1  A: 

If you set the verbose attribute of the nant exec task then it will spit out the exact command line that it generated. Not sure what your specific problem is regarding executing msbuild - I've been using the nantcontrib msbuild task instead.

robaker