Evjen c34.tex V1 - 01/28/2008 4:20pm Page 1536 Chapter 34: Packaging and Deploying ASP.NET Applications Figure 34-5 After being connected to a server, you can copy the contents of your Web application to it by selecting all or some of the files from the Source Web Site text area. After you select these files in the dialog, some of the movement arrows become enabled. Clicking the right-pointing arrow copies the selected files to the destination server. In Figure 34-6 you can see that, indeed, the files have been copied to the remote destination. If you pull up the same copy dialog later, after w orking on the files, you see an arrow next to the files that have been changed in the interim and are, therefore, newer than those on the destination server (see Figure 34-7). These arrows enable you to select only the files that must be copied again and nothing more. All the copying actions are recorded in a log file. You can view the contents of this log file from the Copy Web Site dialog by clicking the View Log button at the bottom of the dialog. This pulls up the CopyWeb- Site.log text file. From the copy that you made previously, you can see the transaction that was done. An example log entry is shown here: Copy from ’C: \ Websites \ Website1’ to ’Y: \ Websites’ started at 10/6/2007 7:52:31 AM. Create folder App_Data in the remote Web site. 1536 Evjen c34.tex V1 - 01/28/2008 4:20pm Page 1537 Chapter 34: Packaging and Deploying ASP.NET Applications Copy file Default.aspx from source to remote Web site. Copy file Default.aspx.cs from source to remote Web site. Copy file Login.aspx from source to remote Web site. Copy file Login.aspx.cs from source to remote Web site. Copy file web.config from source to remote Web site. Copy from ’C: \ Websites \ Website1’ to ’Y: \ Websites’ is finished. Completed at 10/6/2007 7:52:33 AM. Figure 34-6 Deploying a Precompiled Web Application In addition to using Visual Studio to copy a Web application from one location to another, it is also possible to use this IDE to deploy a precompiled application. The process of precompiling a Web appli- cation is explained in Chapter 1. ASP.NET 3.5 includes a precompilation process that allows for a process referred to as precompilation for deployment. What happens in the precompilation for deployment process is that each page in the Web application is built and compiled into a single application DLL and some placeholder files. These files can then be deployed together to another server and run from there. The nice thing about this precompilation process is that it obfuscates your code by placing all page code (as well as the page’s code-behind code) into the 1537 Evjen c34.tex V1 - 01/28/2008 4:20pm Page 1538 Chapter 34: Packaging and Deploying ASP.NET Applications DLL, thereby making it more difficult for your code to be stolen or changed if you select this option in the compilation process. This is an ideal situation when you are deploying applications your customers are paying for, or applications that you absolutely do not want changed in any manner after deployment. Figure 34-7 Chapter 1 showed you how to use the command-line tool aspnet_compiler.exe to accomplish the task of precompilation. Although this is a great method for precompiling your Web applications and deploy- ing them to remote servers, you can also use Visual Studio 2008 to accomplish the precompilation and deployment process. To accomplish t his task, open up the project you want to deploy and get the application ready for deploy- ment by turning off the debugging capabilities as described earlier in the chapter. Then pull up the precompilation and deployment dialog by choosing Build ➪ Publish Web Site in the Visual Studio menu. This opens the Publish Web Site dialog shown in Figure 34-8. Using the Browse ( ) button in this dialog, you can choose any remote location to which you want to deploy the application. As in earlier examples, your options are a file system location, a place in the local IIS, a location accessed using FTP, or a location accessed via FrontPage Server Extensions. Other options in this dialog include the Allow this precompiled site to be updateable check box. When checked, the site will be compiled and copied without any changes to the .aspx pages. This means that after the precompilation process, you can still make minor changes to the underlying pages and the application will work and function as normal. If this check box is unchecked, all the code from the pages is stripped out and placed inside a single DLL. In this state, the application is not updateable because it is impossible to update any of the placeholder files from this compilation process. Another option in this dialog is to assign a strong name to the DLL that is created in this process. You can select the appropriate check box and assign a key to use in the signing process. The created DLL from the precompilation will then be a strong-assembly — signed with the key of your choice. When you are ready to deploy, click OK in the dialog and then the open application is built and published. Published means that the application is deployed to the specified location. Looking at this location, you can see that a bin directory has now been added that contains the precompiled DLL, which is your Web application. This is illustrated in Figure 34-9. 1538 Evjen c34.tex V1 - 01/28/2008 4:20pm Page 1539 Chapter 34: Packaging and Deploying ASP.NET Applications Figure 34-8 In this state, the code contained in any of the ASP.NET-specific pages is stripped out and placed inside the DLL. The files that you see are actually just placeholders that the DLL needs for reference. Building an Installer Program The final option you should look at is how to use Visual Studio to build an installation program. After the program is constructed, a consumer can run the installation program on a server where it performs a series of steps to install the Web application. Packaging your Web application into an installer program works in many situations. For instance, if you sell your Web application, one of the simpler ways for the end user to receive the application is as an executable that can be run on the computer and installed — all without much effort on his part. The Windows Installer The Windows Installer service was introduced with Windows 2000, although it is also available in Windows XP, Windows Server 2003, and Windows Server 2008. This service was introduced to make the installation process for your Windows-based applications as easy as possible. You use the Windows Installer technology not only for ASP.NET applications but also for any type of Windows-based application. The Windows Installer service works by creating a set of rules that 1539 Evjen c34.tex V1 - 01/28/2008 4:20pm Page 1540 Chapter 34: Packaging and Deploying ASP.NET Applications determine how the application is to be installed. These rules are packaged into a Windows Installer Package File that uses the .msi file extension. Figure 34-9 The Windows Installer service considers all applications to be made up of three parts: ❑ Products: The large-bucket item being installed, also known as the application itself. An example of this is the ASP.NET Web application. ❑ Features: Features are subsets of products. Products are made up of one or more features. ❑ Components: Components make up features. A feature is made up of one or more components. A single component can be utilized by several features in the product. The Windows Installer service is a powerful offering and can be modified in many ways. Not only does the Windows Installer technology detail the product, features, and components of what is to be installed, but it can also take other programmatic actions or show a sequence o f user interfaces as the installa- tion process proceeds. For detailed information on the Windows Installer, be sure to view the MSDN documentation on the Windows Installer SDK. With that said, working with the Windows Installer SDK is complicated at best; that was t he reason for the release of the Visual Studio Installer (VSI) as an add-on with Visual Studio 6. This addition made 1540 Evjen c34.tex V1 - 01/28/2008 4:20pm Page 1541 Chapter 34: Packaging and Deploying ASP.NET Applications the steps for building an installer much easier to follow. Visual Studio 2008 continues t o expand on this capability. You have quite a few options for the deployment projects you can build with Visual Studio 2008. Such projects include the following: ❑ Setup Project: This project type allows you to create a standard Windows Installer setup for a Windows application. ❑ Web Setup Project: This is the project type covered in this chapter. It’s the type of setup project you use to create an installer for an ASP.NET Web application. ❑ Merge Module Project: This project type creates a merge module similar to a cabinet file. A merge module, such as a cabinet file, allows you to package a group of files for distribution but not for installation. The idea is that you use a merge module file with other setup programs. This project type produces a file type with an extension of .msm . ❑ Setup Wizard: This selection actually gives you a wizard to assist you through one of the other defined project types. ❑ Cab Project: This project type creates a cabinet file ( .cab ) that packages a group of files for distribution. It is similar to a merge module file, but the cabinet file is different in that it allows for installation of the files contained in the package. ❑ Smart Device Cab Project: This new project type allows for the creation of a cabinet file that is installed on a smart device instead of on a typical operating system. Although you have a number of different setup and deployment project types at your disposal, the Web Setup Project is the only one covered in this chapter because it is the project you use to build an installer for an ASP.NET Web application. Actions of the Windows Installer You might already be thinking that using the Windows Installer architecture for your installation program seems a lot more complicated than using the methods shown previously in this chapter. Yes, it is a bit more complicated — mainly because of the number of steps required to get the desired result; but in the end, you are getting a lot more control over how your applications are installed. Using an installer program gives you programmatic logic over how your applications are installed. You also gain other advantages, such as: ❑ The capability to check if the .NET Framework is installed, as well as which version of the Frame- work is installed ❑ The capability to read or write values to the registry ❑ The capability to collect information from the end user during the installation process ❑ The capability to run scripts ❑ The capability to include such features such as dialogs and splash screens during the installation process Creating a Basic Installation Program You can apply a tremendous amount of customization to the installation programs you build. Let’s start, however, by looking at how to create a basic installation program for your ASP.NET Web application. To 1541 Evjen c34.tex V1 - 01/28/2008 4:20pm Page 1542 Chapter 34: Packaging and Deploying ASP.NET Applications create an installer for your application, first open up the project for which you want to create a deploy- ment project in Visual Studio. The next step is to add an installer program to the solution. To do this, you add the setup program as a new project contained within the same solution. Choose File ➪ New ➪ Project from the Visual Studio menu. This launches the New Project dialog. From the New Project dialog, first expand Other Project Types from the left-hand pane in the dialog and then select Setup and Deployment. This provides you with a list of all the available setup and deployment projects in Visual Studio. For our purposes, select Web Setup Project (shown in Figure 34-10). Figure 34-10 Clicking OK in this dialog adds the Web Setup Project type to your solution. It uses the default name of WebSetup1 . Visual Studio also opens up the File System Editor in the document window, which is shown in Figure 34-11. The File System Editor shows a single folder: the Web Application Folder. This is a representation of what is going to b e installed on the target machine. The first step is to add the files from the WebSite1 project to t his folder. You do this by choosing Project ➪ Add ➪ Project Output from the Visual Studio menu. This pulls up the Add Project Output Group dialog. This dialog (shown in Figure 34-12) enables you to select the items you want to include in the installer program. From this dialog, you can see that the project, Wrox, is already selected. Highlight the Content Files option and click OK. This adds all the files from the Wrox project to the WebSetup1 installer program. This addition is then represented in the File System Editor as well. 1542 Evjen c34.tex V1 - 01/28/2008 4:20pm Page 1543 Chapter 34: Packaging and Deploying ASP.NET Applications Figure 34-11 After the files are added to the installer program, the next step is to click the Launch Conditions Editor button in the Solution Explorer (see Figure 34-13) to open the editor. The Launch Conditions Editor is also displayed in Visual Studio’s document window. From this editor, you can see that a couple of conditions are already defined for you. Obviously, for Web applications, it is important that IIS be installed. Logically, one of the defined conditions is that the program must perform a search to see if IIS is installed before installing the application. You should also stipulate that the installation server must have version 3.5 of the .NET Framework installed. To establish this condition, right-click the Requirements On Target Machine node. Then select Add .NET Framework Launch Condition (as shown in Figure 34-14). This adds the .NET Framework requirement to the list of launch conditions required for a successful installation of the Web application. As a final step, highlight the WebSetup1 program in the Visual Studio Solution Explorer so you can modify some of the properties that appear in the Properties window. For now, you just change some of the self-explanatory properties, but you will review these again later in this chapter. For this example, however, just change the following properties: ❑ Author :Wrox ❑ Description : This is a test project. 1543 Evjen c34.tex V1 - 01/28/2008 4:20pm Page 1544 Chapter 34: Packaging and Deploying ASP.NET Applications ❑ Manufacturer :Wrox ❑ ManufacturerUrl : http://www.wrox.com ❑ SupportPhone : 1-800-555-5555 ❑ SupportUrl : http://www.wrox.com/support/ Figure 34-12 Now the installation program is down to its simplest workable instance. Make sure Release is selected as the active solution configuration in the Visual Studio toolbar; then build the installer program by choosing Build ➪ Build WebSetup1 from the menu. Looking in C: \ Documents and Settings \< username >\ My Documents \ Visual Studio 2008 \ Projects \ Wrox \ WebSetup1 \ Release , you find the following files: ❑ Setup.exe : This is the installation program. It is meant for machines that do not have the Win- dows Installer service installed. ❑ WebSetup1.msi : This is the installation program for those that have the Windows Installer ser- vice installed on their machine. That’s it! You now have your ASP.NET Web application wrapped up in an installation program that can be distributed in any manner you want. It can then be run and installed automatically for the end user. Take a quick look in the following section at what happens when the consumer actually fires it up. 1544 Evjen c34.tex V1 - 01/28/2008 4:20pm Page 1545 Chapter 34: Packaging and Deploying ASP.NET Applications Figure 34-13 Figure 34-14 Installing the Application Installing the application is a simple process (as it should be). Double-click the WebSetup1.msi file to launch the installation program. This pulls up the Welcome screen shown in Figure 34-15. From this dialog, you can see that the name of the program being installed is WebSetup1 . Clicking Next gives you the screen shown in Figure 34-16. 1545 . 10/6/2007 7 :52 :31 AM. Create folder App_Data in the remote Web site. 1 53 6 Evjen c34.tex V1 - 01/28/2008 4:20pm Page 1 53 7 Chapter 34 : Packaging and Deploying ASP. NET Applications Copy file Default.aspx. c34.tex V1 - 01/28/2008 4:20pm Page 154 5 Chapter 34 : Packaging and Deploying ASP. NET Applications Figure 34 - 13 Figure 34 -14 Installing the Application Installing the application is a simple process. contains the precompiled DLL, which is your Web application. This is illustrated in Figure 34 -9. 1 53 8 Evjen c34.tex V1 - 01/28/2008 4:20pm Page 1 53 9 Chapter 34 : Packaging and Deploying ASP. NET