views:

353

answers:

3

How do I compile an ASP.Net MVC project using MSBuild? We use a Continuous Integration server to compile and deploy our applications. To keep things simple I created an MVC 1.0 project in VS2008. I immediately created an MSBuild script file to compile it. I did not change any code in the project. The MSBuild script contained the following target.

   <AspNetCompiler
      VirtualPath="/"
       PhysicalPath="C:\Development\mvc1\"
        TargetPath="c:\publish\xxx"
        Force="true"
        Debug="false" 
 Updateable="true"

The MVC project sln file is contained in the c:\development\mvc1\ directory. I am running XP/Pro.

I am receiving an error ASPCONFIG: it is an error to use a section registered as allowDefintion='MachineToApplication' beyond application level.. I removed the authenication mode, membership provider, etc. from the web config file until I finally saw a different error message. I am now receiving an error message saying that the file '/views/shared/site.master' does not exist.

What is going on? Thanks in advance for your help!

Am I using the wrong MSBuild command?

A: 

You could use NAnt which has a "msbuild" task in it that will just do it for you. NAnt is a great way to go for CI builds.

The NAnt home page The NAnt Contrib home page The MSBuild task reference from NAnt Contrib

...the contrib library adds some great functionality that the vanilla NAnt doesn't have. It is very simple. I've included a snippet of my .build file here so you can see how I've used it:

<property name="DeployDestination" value="\\MyTestServerName\DestinationFolder"/>
<property name="Solution.Configuration" value="Debug" overwrite="True" />
<property name="nant.settings.currentframework" value="net-3.5" />
<if test="${WebContentDestination=='Production'}">
    <property name="DeployDestination" value="\\MyProductionServer\DestinationFolder"/>
</if>

...<snip>

<target name="Build">
    <msbuild project="SolutionFileName.sln">
        <arg value="/p:Configuration=${Solution.Configuration}" />
    </msbuild>
</target>

<target name="Deploy">
    <copy todir="${DeployDestination}" flatten="true" >
        <fileset>All files to copy</fileset>
    </copy>
</target>
Nick DeVore
good any good tutorial links?
Martin
If you use CruiseControl.Net they've got some tutorials on their page. If you use TeamCity same thing. What build server are you using?
Nick DeVore
+2  A: 

If you compile your sln-file (msbuild mysolution.sln) or

<MSBuild Projects="msbuild mysolution.sln" Targets="Rebuild" ContinueOnError="false"
StopOnFirstFailure="false" /><!-- -d -errorstack -->

and the sln-file has the ASP.NET MVC-project .csproj-file then the .csproj-file does have everything you need. Open the .csproj with notepad and look for:

1) This should be true:

<MvcBuildViews>false</MvcBuildViews>

2) Target Name="AfterBuildCompiler":

  <Target Name="AfterBuildCompiler" Condition="'$(MvcBuildViews)'=='true'">
    <AspNetCompiler VirtualPath="SomeVirtualDir" PhysicalPath="C:\Development\mvc1\" TargetPath="c:\publish\xxx\" />
  </Target>

I didn't do anything else and it worked. I actually made my config so that only release build deploy the application (by moving MvcBuildViews-property under PropertyGroups. Then I can use the same .csproj in the development (debug) and deployment (release).

Tuomas Hietanen
thank you Tuomas. this worked for me.
dc
A: 
Malcolm Frexner