1

Using MS Build in ASP.NET Website

by Kalyan.Bandarupalli 25. April 2010 05:04
The Microsoft Build engine is used to build applications based on XML schema. XML schema can be defined in project file which controls the build platform processes.In this post I am going to discuss how to you use MS Build in automating the compilation process for ASP.NET Web site.

1. Create an ASP.NET web site which we can use for the compilation process

image

2. Normally you can use two options to build and deploy the web site. you can copy the entire web site and paste in production box or precomplie the web site and publish the output folder to the production server.

3. This is fine but if you want to control the build process and various build activities then you have to write some scripts to automate the process. This is especially useful when you work on project in team environment where a frequent releases happen and to control the release versions then it would be an ideal choice.

4. If you are new to MS Build then you can read this article for to know the fundamentals.

5. We are using aspnet_compiler command to compile the web site using Build Process.

image

You can see the different for using this command. We are going to use several from the above dialogue in our website.

  • 6. Build script for MS Build is just an xml file contains the different elements which controls the build process. To add a build script to our solution just right click web site add new xml file to the solution and save the file with an extension .proj.
  •  image

7. Write the following elements in the xml file.

image

The root element is project in xml file. To get the intellisense in xml file add the name space element to project tag.

image

The property group element is essentially for defining the properties in build script like we define in class. These properties can be used in our build script.

image

The Target element in the script defines the sequence of operations that we do in build process. you can define as many targets as you can in a single project. The first target element defines the compilation process and second target element defines the merge process.

The final script file will look like the following

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="MergeWebSite" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
     
    <PhysicalPath>[YOUR PHYSICAL PATH HERE]\TestWebsite</PhysicalPath>
    <TargetPath>[YOUR PHYSICAL PATH HERE]\Deployment</TargetPath>
    <VirtualPath>/TestWebsite</VirtualPath>
    <Force>true</Force>
    <Debug>true</Debug>
    <AssemblyName>BuildDemo</AssemblyName>
  </PropertyGroup>
  <Target Name="CompileWebSite">
    <Message Text="Compiling $(VirtualPath)"/>
    <AspNetCompiler
       PhysicalPath="$(PhysicalPath)"
        TargetPath="$(TargetPath)"
        VirtualPath="$(VirtualPath)"
        Force="$(Force)"
        Debug="$(Debug)"/>
  </Target>
  <Target Name="MergeWebSite" DependsOnTargets="CompileWebSite"  >
    <Message Text="Merging compiled site"/>
    <Exec Command='aspnet_merge.exe "$(TargetPath)" -o $(AssemblyName) '
           WorkingDirectory="C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin"
          />
  </Target>
</Project>

8. To Run the above build script from Visual Studio, Add the external tool MSBUILD to your Visual Studio  if it is not in your tools list as follows

image

image

You can find the MSBUILD command line tool at c:\windows\Microsoft.NET\Framework\v3.5

9. Now click on the MS Build in tools menu then you will get the following dialogue box

image

Specify the build script file name and then say ok.

You  can see the Build messages in output window and able to see the Deployment folder under your solution structure which compiles your web site as single dll.

Tags:

ASP.NET

Comments

trackback
Dotnet Sizzler
4/25/2010 5:23:11 AM #

Using MS Build in ASP.NET Website

Using MS Build in ASP.NET Website

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.6.0.0
Original Design by Laptop Geek, Adapted by onesoft