In this practice, you deploy applications by using two techniques: a Web Setup Project and the Copy Web tool.
oN the CoMpaNIoN MedIa
If you encounter a problem completing an exercise, you can find the completed projects in the samples installed from this book’s companion CD. For more information about the project files and other content on the CD, see “Using the Companion Media” in this book’s Introduction.
exercise Creating a Web Setup Project
In this exercise, you create a new ASP.NET website and a related Web Setup Project.
1. Open Visual Studio and create a new website by using the language of your preference.
This site will serve as the basis for your setup project.
2. Add some simple pages to the site. This will give you something to set up and deploy.
These pages could include order.aspx, product.aspx, customer.aspx, and vendor.aspx.
3. Add a Web Setup Project to your solution. To do so, from the File menu, select Add, and then select New Project. Under Project Types, expand Other Project Types, expand Setup And Deployment, and then select Visual Studio Installer. Under Templates (on the right side), select Web Setup Project. Name the project MyWebSetup, and click OK.
You should see a new project in Visual Studio Solution Explorer. You should also see the File System editor for the setup project.
4. Next, you need to connect the setup project to your website. Within the left pane of the editor, right-click Web Application Folder, select Add, and then select Project Output. In the Add Project Output Group dialog box, select Content Files, and click OK.
If you were to build and install your project at this point, it would copy the site pages and code-behind files to the location specified by a user during setup.
5. In the File System editor, expand the Web Application Folder. Notice that there is a Bin directory. This is where you would embed any DLL files that might need to be included by your solution. You would embed these files by right-clicking Bin and selecting Add to add a file. For this practice, there are no dependent DLL files, so you can skip this.
6. Next, add a folder and a file that should be included with the build. To do so, right-click the Web Application Folder in the File System editor. Select Add, and then select Web Folder. Name the folder Images.
7. Right-click the Images folder, select Add, and then select File. Navigate to the Pictures folder on your computer. Select a few sample pictures, and click Open.
Lesson 3: Deploying Websites CHAPTER 8 445 8. Now add a launch condition. From the View menu, select Editor, and then select
Launch Conditions. In the Launch Conditions editor, right-click Requirements On Target Machine, and then select Add File Launch Condition. Rename the new search condition (currently named Search For File1) to Search for Browscap. Select the new search condition and view the Properties window.
■ Set the FileName property to Nothing.ini. (This file doesn’t exist, but you’ll fix the error later.)
■ Set the Folder property to [WindowsFolder] and set the Depth property to 4. This tells setup to search the system folder and all subfolders four levels deep for a file named Nothing.ini. Note that the Property value is set to FILEEXISTS1.
9. Rename the new launch condition (currently named Condition1) to Browscap Condition.
Select the new launch condition and view the Properties window.
■ Set the InstallUrl property to http://blogs.iis.net/dmnelson/archive/2009/05/14 /updating-browscap-ini-for-internet-explorer-8.aspx, which contains informa-tion about the Browscap.ini file. In the real world, you would provide a link with instructions on how to fulfill the requirement.
■ Set the Message property to You must have a Browscap.ini file to complete installation. Would you like more information?. Notice that the Condition property is already set to FILEEXISTS1, which corresponds to the search condition Property value.
10. Build the Web Setup Project. Right-click your setup project in Solution Explorer and then select Build. In the Output window, make note of the folder containing the output files.
Open the output folder in Windows Explorer and examine the files that are present. You should see both an MSI and a setup.exe file.
11. Open the folder that contains the MSI file. Double-click the MSI file to launch setup.
After a few seconds, you should see an error message indicating that the Browscap.ini file does not exist, as shown in Figure 8-27.
fIGURE 8-27 The MSI file error message.
Recall that we added this condition in step 9. We also set the FileName property of the search condition to Nothing.ini in step 8, which is why this error is being thrown.
12. Click Yes. You will be taken to the InstallUrl set as part of the condition.
13. Return to Visual Studio. Open the Launch Conditions editor for the Web Setup Project.
14. Select Search For Browscap under Search Target Machine. View the Properties window.
Change the FileName property to look for the file Browscap.ini.
15. Rebuild the Web Setup Project (right-click and select Rebuild).
16. Return to the directory in which the MSI file exists. Rerun the MSI file. This time, the computer should meet the setup requirements because the Browscap.ini file exists in the Windows folder.
Note INSTALLATIoN ISSUES
Depending on your environment, you might run into additional issues. If, for example, you are running Windows Vista and IIS 7.0, you need an IIS 6-compatible metabase for the IIS condition to validate. You can tweak the condition or add the IIS 6 metabase to IIS 7.0 from Control Panel (classic view) | Programs And Features | Turn Windows Feature on or off | Internet Information Services | Web Management Tools | IIS 6 Management Compatibility. Another issue is security in Windows Vista and Windows 7. You might have to run the Setup.exe file (and not the MSI file) by right-clicking Setup.exe and selecting Run As Administrator.
17. On the Select Installation Address page, notice that you have the opportunity to select the website, virtual directory, and application pool. Choose a unique virtual directory name and make note of it. Click Next.
18. Finish walking through the installation steps.
19. Open the Internet Information Services console (Control Panel | Administrative Tools
| Internet Information Services [IIS] Manager). Find the virtual directory in which you installed the website. Verify that the pages, code-behind files, and images exist.
As you can see, deploying a website can be as easy as installing a Windows Forms applica-tion. Although this process takes you through a manual installation of a Windows Installer package, you can also deploy the MSI file in an automated manner.
Lesson Summary
■ Web Setup Projects allow you to create executable Setup.exe files and Windows Installer packages (MSI files) that administrators can use to easily deploy your applications to a web server.
■ The Copy Web tool can synchronize a website between a remote server and your local computer. This is useful if you want to do deployment and testing on your local computer and then upload the website to a remote web server. The Copy Web tool can also be use-ful in environments with multiple developers because it detects versioning conflicts.
■ Precompiling a website removes the delay that occurs when ASP.NET compiles an application after the first user request. To precompile a website, use the Publish Web Site tool.
Lesson 3: Deploying Websites CHAPTER 8 447
Lesson Review
You can use the following questions to test your knowledge of the information in Lesson 1,
“Deploying Websites.” The questions are also available on the companion CD in a practice test, if you prefer to review them in electronic form.
Note ANSWERS
Answers to these questions and explanations of why each answer choice is correct or incorrect are located in the “Answers” section at the end of the book.
1. You need to add a registry entry to make your application function. In which phase of the Web Setup Project should you add the registry entry?
a. Install B. Commit c. Rollback D. Uninstall
2. You need to make a change to an operating system–related registry entry to make your application function. You want to ensure that you remove this change if setup is cancelled or the application is removed from the computer. In which phases should you undo your registry modification? (Choose all that apply.)
a. Install B. Commit c. Rollback D. Uninstall
3. Which of the following deployment tools enables multiple developers to work on a site simultaneously while detecting potential versioning conflicts?
a. A setup project B. A Web Setup Project c. The Copy Web tool D. The Publish Web Site tool
4. Which of the following deployment tools has the potential to improve responsiveness of the website to end users?
a. A setup project B. A Web Setup Project c. The Copy Web tool D. The Publish Web Site tool