Deploying Crystal Report Intranet Web Application Using MSBuild
 
Published: 02 Mar 2006
Unedited - Community Contributed
Abstract
An article discussing how to deploy a Crystal web intranet application to a Dev/Testing and Production environment, using MSBuild.
by Eric Landes
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 18392/ 22

Introduction

Visual Studio 2005 introduces the MSBuild tool for compiling and building your applications.  Before Visual Studio 2005, the build tools were bundled within Visual Studio as a proprietary application.  Those of us who utilized build processes outside of an IDE were forced to use tools like Makefile and NAnt.  While tools like NAnt are being upgraded for .Net 2.0, with the advent of MSBuild, all you need now is the .Net framework.  No additional downloads are necessary.

For the last 8 years, I have worked in corporate environments as an Intranet developer.  Most of these environments included a Development, Quality Assurance, or Testing environment and a Production environment.  For anyone in an environment like this, an automated build process for your application is essential. 

The automated build process assures consistency for testing custom applications.  By always having a process that builds your application the same way every time, changes are caught, files get copied to the same directory every time, and things like unit tests and documentation can be run.

To consistently make sure that you put the build process into each application, make sure to have "Creating the Build Process" or something similar as a task in your project plan.  Making that task part of your project plan ensures consistent builds across your environments.  You are also forced to make deliberate changes (for instance, adding a new dll to the gac, and other tasks that affect the server environment).

In this article, I wanted to show how to deploy your Crystal Report application to a different environment that might not have Visual Studio 2005 installed. 

System Requirements

.Net Framework 2.0 and an editor (I use Visual Studio 2005)

Deploying Intranet Web Apps

Using Visual Studio 2005, Microsoft has made deploying your web applications easier.  They have created the "Visual Studio Web Deployment Projects" download.  Installing this gives the user an option on the Build menu to create a Web Deployment project.  Using the GUI shown in Figure 1, you can do some of the things you want, like changing a connection string in your web.config.  Utilizing this tool helps you to get started with your build file quickly.   

In this scenario, we are setting up for an initial deploy to our development environment.   Let's start with the Dev scenario.  For each scenario, there are a few steps to add.  First, create a build directory (check it, then delete files out of it).  Next, copy the files from the source directory of the application. This step could also get your source files from your Source Control provider and place them into the build directory.   Then we compile the project.  Finally, we copy the files, including the Crystal Report and Crystal assemblies, to the destination directory of the dev server.  Now let's see how that's done.

Look at the file that you created by clicking "Add Web Deployment Project" from the Build menu.

Figure 1

The web Deployment project, once open, has xml elements, including Projects.  For a complete description of MSBuild and its tasks, check this link.  MSBuild, like NAnt, utilizes targets to section off different work areas.  For an overview of MSBuild, go to this link.

In this example, in the Project tag, we put the default target as DEV_Build.  If you are familiar with NAnt, then the way targets work should be familiar for you.  For instance, before the DEV_Build target fires, if the DependsonTarget tag contains a name, that fires before the tag.  Below in Code Listing 1 is a sample of how that works.

Code Listing 1

  <Target Name="DEV_Build" DependsOnTargets="DEV_BeforeBuild">

So the above target depends on DEV_BeforeBuild.  In the case of this build file there is also a DEV_Clean target. 

The Dev_Build target compiles the project, then copies the report file, aspx file and the web.config file.  There are ways to modify the web.config in your build file for the environment you wish to send the information to.  Finally, the dependent assemblies are copied to the projects bin directory.  Code Listing 2 has the entire build file for a dev environment for a simple Crystal Web file.

Code Listing 2

<Project DefaultTargets="DEV_Build" 
  xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
 <BuildDirectory>c:\build\</BuildDirectory>
    <SourceDirectory>C:\Dev\MSBuildCrystalExample\</SourceDirectory>
    <CrystalSourceDirectory>C:\Program Files\Common Files\Crystal Decisions\1.1\Managed\</CrystalSourceDirectory>
 <DevDirectory>c:\inetpub\wwwroot\SampleDevServer\</DevDirectory>
    <ProgramName>MSBuildCrystalExample</ProgramName>
 <AppName>CrystalBuildSample</AppName>
 
  </PropertyGroup>
  <ItemGroup>
  </ItemGroup>
  <Import Project="$(MSBuildExtensionsPath)\Microsoft\WebDeployment\v8.0\Microsoft.WebDeployment.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.WebDeployment.targets.-->
  <Target Name="DEV_Clean">
    <Delete Files="$(BuildDirectory)$(ProgramName)\*.*" TreatErrorsAsWarnings="true"></Delete>    
  </Target>
  <Target Name="DEV_BeforeBuild" DependsOnTargets="DEV_Clean">
    <MakeDir Directories="$(BuildDirectory)$(ProgramName)" ContinueOnError="true"></MakeDir>
    <MakeDir Directories="$(BuildDirectory)$(ProgramName)\bin" ContinueOnError="true"></MakeDir>
    <!-- Copy aspx files, then others-->
    <Copy
 SourceFiles="$(SourceDirectory)default.aspx;$(SourceDirectory)
   CrystalReport1.rpt;$(SourceDirectory)Default.aspx.cs;$(SourceDirectory)web.config"
 DestinationFiles="$(BuildDirectory)$(ProgramName)\default.aspx;$(BuildDirectory)$(ProgramName)
   \CrystalReport1.rpt;$(BuildDirectory)$(ProgramName)\Default.aspx.cs;$(BuildDirectory)$(ProgramName)\web.config"
        />
    <Copy
 SourceFiles="$(CrystalSourceDirectory)CrystalDecisions.CrystalReports.Engine.dll;
   $(CrystalSourceDirectory)CrystalDecisions.Shared.dll;
   $(CrystalSourceDirectory)CrystalDecisions.Web.dll"
 DestinationFiles="$(BuildDirectory)$(ProgramName)\bin\CrystalDecisions.CrystalReports.Engine.dll;
   $(BuildDirectory)$(ProgramName)\bin\CrystalDecisions.Shared.dll;
   $(BuildDirectory)$(ProgramName)\bin\CrystalDecisions.Web.dll"
        />
 
  </Target>
  <Target Name="DEV_AfterBuild" DependsOnTargets="DEV_Build">
  </Target>
  <Target Name="DEV_Build" DependsOnTargets="DEV_BeforeBuild">
    <Csc Sources="$(BuildDirectory)$(ProgramName)\*.cs" 
      OutputAssembly="$(BuildDirectory)$(ProgramName)\msbuildexample.dll" 
      EmitDebugInformation="false"></Csc>
  </Target>
 
</Project>

Within this deployment project, there are tasks for deploying to a dev server.  You can then add similar targets for your testing environment. 

Summary

This article gave you an introduction to creating a build file with MSBuild for your Intranet Crystal Web Project.  Creating an automated build process can add stability to your development process.  This is one step toward that automated build process.  



User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 



Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-20 10:55:04 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search