views:

795

answers:

6

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.

A: 

My best guess is that the ASP.Net mvc dll's are not installed on the build server. ASP.Net MVC is a separate download.

Shiraz Bhaiji
The problem is, this is running on my local dev PC... I can literally build the project in Visual Studio, exit out and open up a Command Window to run my NAnt script and it fails...!
Brett Rigby
OK. New guess: you are opening the "command prompt" not the "visual studio prompt". The difference is the path. Since the path is missing it cannot find the dll.
Shiraz Bhaiji
No, I have set-up my command prompt environment variables as the builds require - regular ASP .Net websites and other component files build fine...
Brett Rigby
+1  A: 

Not exactly an answer to your question but more a different tack that might solve what you wish to achieve.

I find studio to be more friendly that the asp compiler from the command line.

Could you not build it with devenv.exe through a NAnt command line task.

Best of luck,

Dan

Daniel Elliott
Interesting take on things. I'll look into it.
Brett Rigby
You're right, the aspnet_compiler.exe is WAY more harsh than the Visual Studio compiler!!
Brett Rigby
+3  A: 

Installing the MVC bits on the build box should sort this out--it is either lacking the .dlls to know your Home.Index view descends from System.Web.Mvc.ViewPage or it doesn't have the right project template for the compiler to use.

Wyatt Barnett
No, I'm not running the scripts on the build machine - I'm running them locally PRIOR to running them on the build machine, as a pre-check-in test. But as they don't run on the local dev machine, I have to mute-out code as it'll break the build machine.
Brett Rigby
+3  A: 

You shouldn't install ASP.NET MVC onto the build box. You should be referencing the System.Web.MVC, System.Web.Routing and System.Web.Abstractions DLLs from wherever you store your third-party references. We normally have a /lib folder for all references where we have those 3 DLLs (and many more) stored and a /src folder where all of our code lives. If you are referencing these DLLs this way, you no longer have to rely on the environment for those DLLs. This blog post explains this idea in more detail.

J.R. Garcia
That's exactly what I'm doing - I'm using Ivy to resolve my MVC site's dependencies into the Lib folder, where the code references them from. The build server doesn't have any additional MVC components installed.
Brett Rigby
+1  A: 

On a project I was working on recently we build the ASP.NET MVC web app using this target:

<target name="CompileSite" depends="blah blah">
    <exec program="${framework::get-framework-directory('net-2.0')}\aspnet_compiler.exe" commandline="-p &quot;${SrcDir}\Website&quot; -v / -d &quot;${CompiledSiteOutputDir}&quot; -fixednames" workingdir="${BaseDir}" />
</target>

so it is definitely possible. Our views were named something like ProjectName.Views.News.List etc.

Could you provide more details? Does the compiler say where it encounters the error (file, linenumber etc.)?

Rune
+2  A: 

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>
Lachlan Roche
Thank you very much - This works great! I was missing a few of the parameters that you set-out above.
Brett Rigby