views:

862

answers:

4

Is it possible to accomplish publish (as in Visual Studio publish on Web Application project) on solution using NAnt? I just can't find the solution.

+3  A: 

They key is to use the built-in "_CopyWebApplication" target.

Here is what i do

<target name="compile" description="Compiles the project.">
     <exec basedir="." program="${DotNetPath}msbuild.exe" commandline=" src/MyProject.Web/MyProject.Web.csproj /nologo 
  /t:Rebuild
  /t:ResolveReferences;_CopyWebApplication
  /p:OutDir=../../output/build/bin/
  /p:WebProjectOutputDir=../../output/build/
  /p:Debug=${debug}
  /p:Configuration=${configuration}
  /v:m"
    workingdir="." failonerror="true" />
    </target>

with the dir structure of:

/project.build
/src/myprojct.sln
/src/myporject.web/myproject.web.csproj
/output

Edit: i also use this to use the YUI compression to compress my css and js

<target name="compress-js">
     <foreach item="File" property="filename">
      <in>
       <items basedir="output/build/assets/javascript/">
        <include name="/**/*.js" />
        <exclude name="/**/*.min.js" />
        <exclude name="/**/*.pack.js" />
       </items>
      </in>
      <do>
       <exec basedir="." program="${JavaPath}java" commandline=" -jar S:\yuicompressor-2.4.1\build\yuicompressor-2.4.1.jar --type js --charset utf-8 -o &quot;${filename}&quot; &quot;${filename}&quot;" failonerror="true" />
      </do>
     </foreach>
    </target>


    <target name="compress-css" depends="combine-css">
     <foreach item="File" property="filename">
      <in>
       <items basedir="output/build/assets/css/">
        <include name="/**/*.css" />
        <exclude name="/**/*.min.css" />
        <exclude name="/**/*.pack.css" />
       </items>
      </in>
      <do>
       <exec basedir="." program="S:\Java\jdk1.6.0_11\bin\java" commandline=" -jar S:\yuicompressor-2.4.1\build\yuicompressor-2.4.1.jar --type css --charset utf-8 -o &quot;${filename}&quot; &quot;${filename}&quot;" failonerror="true" />
      </do>
     </foreach>
    </target>
Andrew Bullock
+2  A: 

Using MSBuild beats the purpose of using NAnt, NAnt is something that replaces MSBuild, use the below to do a clean NAnt compilation of Web Application Projects as in VS 2003/2005/2008.

It works for me!

<?xml version="1.0"?>
<project name="MyTest" default="run">
    <property name="basename" value="MyTest1x"/>
    <property name="debug" value="false"/>
    <property name="copytarget" value="c:\temp"/>

    <target name="clean">
        <delete>
            <fileset basedir="${copytarget}">
                <include name="bin/${basename}.dll"/>
                <include name="**/*.???x"/>
                <include name="Web.config"/>
            </fileset>
        </delete>
    </target>

    <target name="build">
        <mkdir dir="${copytarget}/bin" />
        <csc target="library" output="${copytarget}/bin/${basename}.dll" >
            <sources>
                <include name="*.cs"/>
            </sources>
        </csc>
    </target>

    <target name="run" depends="clean,build">
    <copy todir="${copytarget}" overwrite="true">
      <fileset basedir=".">
             <include name="**/*.???x" />
             <include name="Web.config" />
          </fileset>
       </copy>
   </target>
</project>
Binoj Antony
+2  A: 

Here is how you can do it using the MSBUILD task for nant:

<property name="debug" value="AutomatedDebug" />
<property name="configuration" value="Debug;TargetFrameworkVersion=v3.5" />

    <msbuild project="src\WebApplication1\WebApplication1.csproj" failonerror="true">
      <arg value="/nologo" />
      <arg value="/t:Rebuild" />
      <arg value="/t:ResolveReferences;_CopyWebApplication" />
      <arg value="/p:OutDir=../../build/Debug/WebApplication/" />
      <arg value="/p:WebProjectOutputDir=../../build/Debug/WebApplication-Deploy/" />
      <arg value="/p:Debug=${debug}" />
      <arg value="/p:Configuration=${configuration}" />
      <arg value="/v:m" />
    </msbuild>

This will compile the WebApplication into a deployable folder, just like using the "Publish" feature from within Visual Studio.

David P
A: 

What do the /t: and /v: switches do for msbuild ?

 <arg value="/t:ResolveReferences;_CopyWebApplication" /> 
 <arg value="/v:m" /> 
diegohb