NAnt <msbuild> custom output directory

夙愿已清 提交于 2019-12-03 14:32:18

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>

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.

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.

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 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.

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 ?

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>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!