Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publish WebApplication using NAnt

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.

like image 557
rafek Avatar asked Dec 04 '22 15:12

rafek


2 Answers

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>
like image 53
Andrew Bullock Avatar answered Dec 27 '22 13:12

Andrew Bullock


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>
like image 44
Binoj Antony Avatar answered Dec 27 '22 14:12

Binoj Antony