asp.netasp.net-mvcnant

Using the ASP Compiler in NAnt to build an ASP .Net MVC application


I am succesfully building ASP .Net applications in NAnt using the ASP Compiler, without a problem., as part of my Continuous Integration process.

However, if I try exactly the same process on an ASP .NET MVC application, the build fails in NAnt, but will compile succesfully in Visual Studio. The error message I get in NAnt is:

[HttpParseException]: Could not load type 'MyNamespace.Views.Home.Index'

which appears that it has a problem with the dots in the filenames, but I might be wrong.

Any suggestions are most welcome.


Solution

  • The MVC app needs to be built as a project before using aspnet_compile. If your MVC project uses other class library projects, they also need to be compiled.

    After running aspnet_compile, we then want to delete various files that should not be part of the deployed site.

    This build file is located in the parent directory to my project MvcApplication.

    <project default="build">
        <property name="build.dir" value="${project::get-base-directory()}"/> 
        <property name="build.config" value="Release" />
    
        <target name="build">
    
            <exec program="${framework::get-framework-directory('net-3.5')}/msbuild.exe">
                <arg value="/property:Configuration=${build.config}" />
                <arg value="${build.dir}/MvcApplication/MvcApplication.csproj" />
            </exec>
    
            <delete dir="${build.dir}/PrecompiledWeb" includeemptydirs="true" failonerror="false"/>
    
            <exec program="${framework::get-framework-directory('net-2.0')}/aspnet_compiler.exe">
                <arg value="-v" />
                <arg value="/" />
                <arg value="-p" />
                <arg value="MvcApplication/" />
                <arg value="-f" />
                <arg value="PrecompiledWeb" />
            </exec>
    
            <delete verbose="true" includeemptydirs="true" failonerror="false">
                <fileset basedir="${build.dir}/PrecompiledWeb">
                    <include name="Controllers" />
                    <include name="Properties" />
                    <include name="obj/**" />
                    <include name="obj" />
                    <include name="*.csproj" />
                    <include name="*.csproj.user" />
                </fileset>
            </delete>
    
        </target>
    </project>