tags:

views:

5152

answers:

7

I'm new to NAnt and have been able to create a which

1) Deletes any code from the current folder

2) Exports fresh code from SVN

3) Builds the code in the default directory which is the PrecompiledWeb folder (its a web app)

Here it is:

<target name="export" description="export code from svn">
 <delete dir="${Delete.Dir}"></delete>
 <exec program="svn" commandline="export ${MySVN.Repos} ${MySVN.Dest}" />
 <msbuild project="${Solution.Filename}">
     <property name="Configuration" value="Release"/>
    </msbuild>
</target>

I want to specify a custom output directory (other than "PrecompiledWeb"). Is this possible and could you please show me the necessary tag/property?

Thank you!

EDIT

Thanks to Scott and Si, I'm getting closer to a solution, but I still don't have anything that works. There comments led me to this article on MSBuild's Output Path Property. Using their code:

<?xml version="1.0"?>
<project name="test" default="build" basedir="." xmlns="http://nant.sf.net/schemas/nant-0.84.win32.net-1.0.xsd"&gt;
    <target name="build">
        <exec program="${framework::get-framework-directory('net-3.5')}/msbuild.exe">
          <arg value="${Full.Path}\Code\eForms.sln" />
          <arg value="/p:OutputPath=${Full.Path}\Output\" />
        </exec>
    </target>
</project>

This will sucessfully run; however, in my solution which contains a web site and a class library, it publishes the class library dll to the specified output path, but it still publishes the actual web site to the default PrecompiledWeb folder.

Does anyone have any suggestions for how to change the PrecompiledWeb folder path from NAnt?

Thanks again to everyone who's helped!

+5  A: 

One can specify and override some of properties for msbuild. In order to specify the output directory, override the OutputDir property.

<target name="export" description="export code from svn">
        <delete dir="${Delete.Dir}" />
        <exec program="svn" commandline="export ${MySVN.Repos} ${MySVN.Dest}" />
        <msbuild project="${Solution.Filename}">
            <property name="Configuration" value="Release"/>
            <property name="OutputDir" value="${Output.Dir}"/>
        </msbuild>
</target>
Scott Saad
Maybe i'm doing something wrong, but even after adding that property tag, it still publishes to the PrecompiledWeb folder inside the solution folder. Do you have any idea why this may be? Thanks for your help regardless.
Michael La Voie
Is this a web solution?
Scott Saad
Ahh... just saw in your answer that it is indeed a web app.
Scott Saad
+5  A: 

Just had a quick peek at a project, does OutputPath instead of OutputDir help?

Another option might be a web deployment project, which I like because it calls aspnet_compiler as well as the C# compiler, so it picks up issues which you may otherwise miss until deployment.

Si
+2  A: 

A build script for one of our projects uses this command to publish a web application:

msbuild.exe /t:_CopyWebApplication /p:Configuration=Release /p:OutDir=.\..\published\ /p:WebProjectOutputDir=.\..\published

(The current directory is set to the web app's project directory at this point, which is why no .csproj file is specified. The entire solution has already been rebuilt earlier in the script.)

By the sound of it, WebProjectOutputDir might be the property you need.

/t:_CopyWebApplication may also be important. I've not used NAnt so I don't know if you can pass this parameter with the msbuild task. You may need to use an exec task, like in this example: http://www.netomatix.com/development/wapwithnant.aspx. This example appears to rebuild and copy all in one go.

David James
+1  A: 

A source of confusion is that you're blending two distinct build systems. Your NAnt target is delegating all the work of figuring out how to publish your web application to the solution file, hence by extension to the csproj files it references.

csproj files are MsBuild files, so you should probably look there for how to direct your project output. This post by dave^2 might be helpful on that issue.

You can publish your web application wherever you want using NAnt, provided it's doing the publishing. You can do the same with MsBuild. The cause of your quandary is that NAnt is not doing the publishing in this case, and you're letting the csproj file determine the location of your web directory. So either bypass the csproj file and have NAnt (or MsBuild) publish the code; or modify the csproj file to publish the web application where you want; or make a second location for your web application and publish it there as well using your build tool.

AFAIK, those options are exhaustive.

Adam
A: 

Hmm, don't know how to do it with MSBuild in Nant, but using NAnt, I've done it previously like this:

<solution solutionfile="${build.dir}\solution.sln">
    <webmap>
       <map url="http://localhost/somdir/project.csproj"
            path="c:\inetpub\wwwroot\somelocaldir" />
    <webmap>
</solution>

But then, you're using the NAnt 'solution' task offcourse instead of using MSBuild directly.

edit: I'm also having a look at some msbuild options; If you set OutDir & OutputPath to the same value, what happens ?

Frederik Gheysels
Thanks, but this is a .NET 3.5 project and I don't think the <solution> tag support .NET 3.5.
Michael La Voie
A: 

When using the task, the correct property name is OutDir, not OutputDir:

    <msbuild project="${Solution.Filename}">
        <property name="Configuration" value="Release"/>
        <property name="OutDir" value="${Output.Dir}"/>
    </msbuild>
A: 

Try something like this:

<property name="nant.settings.currentframework" value="net-3.5"/>    
<msbuild project="${Solution.Filename}">
    <property name="Configuration" value="Release"/>
    <property name="OutDir" value="${Full.Path}\Output\\"/>
    <property name="WebProjectOutputDir" value="${Full.Path}\Output\Web\\"/>
</msbuild>
Shawn