Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NAnt <msbuild> custom output directory

Tags:

msbuild

nant

I'm new to NAnt and have been able to create a <target> 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">
    <target name="build">
        <exec program="${framework::get-framework-directory('net-3.5')}/msbuild.exe">
          <arg value="${Full.Path}\Code\MySolution.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!

Edit 2 Final Solution

Here is what I finally was able to get working (updated for .net 4):

<exec program="${framework::get-framework-directory('net-4.0')}/msbuild.exe">
    <arg value="${Full.Path}\Code\MySolution.sln" />
    <arg value="/t:Rebuild" />
    <arg value="/t:ResolveReferences" />
    <arg value="/t:_CopyWebApplication" />
    <arg value="/p:OutDir=${Build.Output}bin\" />
    <arg value="/p:WebProjectOutputDir=${Build.Output}" />
    <arg value="/p:Configuration=Release" />
</exec>
like image 367
Michael La Voie Avatar asked Feb 25 '09 20:02

Michael La Voie


4 Answers

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>
like image 148
Scott Saad Avatar answered Nov 10 '22 08:11

Scott Saad


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.

like image 25
si618 Avatar answered Nov 10 '22 08:11

si618


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.

like image 35
David James Avatar answered Nov 10 '22 08:11

David James


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>
like image 45
Holistic Developer Avatar answered Nov 10 '22 07:11

Holistic Developer