Deploying Crystal Report Intranet Web Application Using MSBuild
page 2 of 3
by Eric Landes
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 18388/ 32

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. 


View Entire Article

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-26 3:26:55 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search