NAnt <msbuild> custom output directory
Asked Answered
H

7

7

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>
Holds answered 25/2, 2009 at 20:19 Comment(1)
If you use a web deployment project you can define OutputPath for the whole website. Other than that, perhaps you will need to delve into the Microsoft MSBuild scripts?Draughtboard
F
9

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>
Farandole answered 25/2, 2009 at 21:56 Comment(2)
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.Holds
Ahh... just saw in your answer that it is indeed a web app.Farandole
D
7

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.

Draughtboard answered 27/2, 2009 at 2:49 Comment(0)
T
5

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.

Tailband answered 14/3, 2009 at 10:45 Comment(0)
M
4

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>
Mica answered 13/7, 2009 at 19:33 Comment(0)
A
1

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.

Admire answered 14/3, 2009 at 12:38 Comment(0)
B
0

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 ?

Banjo answered 16/3, 2009 at 8:7 Comment(1)
Thanks, but this is a .NET 3.5 project and I don't think the <solution> tag support .NET 3.5.Holds
D
0

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>
Derision answered 24/8, 2009 at 13:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.