Publish WebApplication using NAnt
Asked Answered
B

4

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.

Bozen answered 31/3, 2009 at 13:12 Comment(0)
C
7

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>
Craving answered 31/3, 2009 at 13:26 Comment(0)
N
5

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>
Novelty answered 24/4, 2009 at 7:17 Comment(0)
A
3

I know this is an old question, but I just learned something, so I decided I'd share: While it is 100% true that the "_CopyWebApplication" target exists and works, as of .NET 4.0 it has been superseded by the "_WPPCopyWebApplication" target in Microsoft.Web.Publishing.targets, which supports new features like web.config transformation syntax, etc.

(reposting to all the similarly worded questions, so don't vote for this one :) )

Adaptable answered 3/4, 2012 at 15:1 Comment(1)
I know you said not to vote for this one, however this answer helped me a lot and it doesn't deserve to be stowed right at the bottom of the answers, even if it is supplemental to the main answer. :)Kermanshah
L
2

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.

Lahr answered 29/5, 2009 at 2:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.