Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

C# ПІДРУЧНИКИ / c# / Premier Press - C# Professional Projects

.pdf
Скачиваний:
475
Добавлен:
12.02.2016
Размер:
14.7 Mб
Скачать

268 Project 1 CREATING A CUSTOMER MAINTENANCE PROJECT

 

 

Y

 

L

 

F

 

M

 

A

 

E

 

FIGURE 12-6 Contents of the .osd file

 

T

 

 

For huge projects, a CAB project may not be sufficient to deploy an application. Therefore, you can combine the CAB project option with the other options provided by Visual Studio .NET. For example, consider the Customer Maintenance project that we have created for CareKar, Inc. This project includes several resource files, such as .xsd files, that contain information about the datasets created to access the tables in the CMS (Customer Maintenance System) database. Because these .xsd files are included in the application, they need to be distributed as a part of the application.In such a scenario, it would be appropriate to first convert the application into a CAB file and then create a Setup project. I will discuss the Setup project in the following section.

The Setup Project

Another deployment project that Visual Studio .NET provides you is the Setup project.The Setup Project template creates the installer files that users can install on their machines to deploy the application. The installer files created by the Setup Project template are called MSI (Microsoft Windows Installer) files. These files have an extension of .msi and can be installed on the user’s machine by using the Microsoft Installer service.

Team-Fly®

DEPLOYING A WINDOWS APPLICATION

Chapter 12

269

 

 

 

 

The Setup Project template creates the MSI files for your application, which include the application files, the resource files, and the information required for the deployment of the application. This information includes the registry information and the steps for the successful installation of the application. In addition, the MSI files include the Visual Studio. NET runtime files that are required for the execution of the Windows application.

THE MICROSOFT INSTALLER SERVICE

The Microsoft Installer service is an installation service provided by Microsoft to optimize the process of deploying an application. For example, the Microsoft Installer service installs the files required for the successful deployment of an application or the component of an application. This service is available as a part of Microsoft Windows 2000 and higher operating systems.

You will now create a Setup project for

the Customer Maintenance project by using the Setup templates provided by Visual Studio .NET. Visual Studio .NET provides separate templates for deploying the Windows application and Web applications.The template used to deploy the Windows application,the Setup Project template, creates the MSI files for the application on the user’s computer. The template used to deploy Web applications, the Web Setup Project template, creates the MSI files in a virtual directory present on a Web server. In this chapter, I will be discussing the deployment of the Windows application by using the Setup Project template.

To create a Setup project for the Customer Maintenance project, perform the following steps:

1.On the File menu, point to the Add Project option.

2.From the list that is displayed, select the New Project option. The Add New Project dialog box is displayed.

3.From the Project Types: pane, select the Setup and Deployment Projects option.

4.In the Templates: pane, select the Setup Project option.

5.In the Name: text box, type the name of the Setup project as CustomerMaintenanceSetupProject.

6.Click on the Browse button to browse to the location where you want to save the Setup project.

7.Click on the OK button to close the Add New Project dialog box.

270 Project 1 CREATING A CUSTOMER MAINTENANCE PROJECT

The Setup Project template creates a file system editor, which is displayed by default. You can also access the file system editor from the View menu. In addition to the file system editor, the View menu provides several other editor options, such as Registry, File Types, User Interface, Custom Actions, and Launch Conditions. To access the editors provided by Visual Studio .NET, perform the following steps:

1.Right-click on CustomerMaintenanceSetupProject in the Solution Explorer window.

2.In the displayed list, point to the View menu.

The list of file editors is displayed. You can click on any of these options to display the corresponding information. You will learn more about the editors later in this chapter.

Figure 12-7 displays the file system editor as created on the user’s machine.

FIGURE 12-7 File system editor as created on the user’s machine

As you can see, the folders in the file system editor, such as Application Folder, User’s Desktop, and User ’s Program Menu, are empty. This is because you have not added the output files to the Setup project. You will learn to add the output files later in this chapter.

DEPLOYING A WINDOWS APPLICATION

Chapter 12

271

 

 

 

 

The Add option of CustomerMaintenanceSetupProject provides you with two options in addition to the Project Output and File options. These additional options are Folder and Assembly.

Folder. The Folder option allows you to add a new folder to the file system editor.

Assembly. The Assembly option allows you to add Visual Studio .NET components from the Component Selector dialog box. The Component Selector dialog box contains a list of components, their versions, and their locations on the hard disk, which you may need to add to the user’s machine. Figure 12-8 displays the Component Selector dialog box.

FIGURE 12-8 The Component Selector dialog box

After seeing the options available on the Add menu, you can continue with the process of creating a Setup project. In this project, you will be adding only Project Output. However, you may add the other options to your project, if required.

1.In the user interface for the file system editor, right-click Application Folder.

2.In the displayed list, point to the Add menu and then select the Folder option.

272 Project 1 CREATING A CUSTOMER MAINTENANCE PROJECT

Visual Studio .NET adds a new folder to the file system editor. Alternatively, you can add a new folder by clicking on the Action menu. In the displayed list, point to the Add menu and then select the Folder option.

3.Name this folder Output.

You may give any name to the folder.

4.On the Action menu, point to the Add option.

5.Select the Project Output option to add the required files to the Setup project.

The Add Project Output Group dialog box is displayed.

6.In the Add Project Output Group dialog box, select the Primary Output option.

The Primary Output is created in the Output folder.

You saw the user interface for the file system earlier. The folders did not contain the output files.After adding the Project Output file to the Setup project, the user interface for the file system appears as shown in Figure 12-9.

FIGURE 12-9 The user interface for the file system editor

DEPLOYING A WINDOWS APPLICATION

Chapter 12

273

 

 

 

 

After creating the output file, you need to build the Setup project by performing the following steps:

1.Click on the Build menu.

2.From the drop-down list, select the Build CustomerMaintenanceSetupProject option.

Building the project creates a MSI file that can be easily deployed on the user’s machine. The location and other properties of the MSI file are displayed in the Properties window of the Primary Output file. Figure 12-10 shows the CustomerMaintenanceProject.msi file.

FIGURE 12-10 The CustomerMaintenanceProject.msi file

You can distribute the CustomerMaintenanceProject.msi file that you have created in several ways, such as floppy disks or compact discs. To do this, copy the MSI file that is created to the distribution medium and then run the installation program on the user’s machine.

Perform the following steps to install the Windows application on the user’s machine.

1. Copy the CustomerMaintenanceProject.msi file to the user’s machine.

274Project 1 CREATING A CUSTOMER MAINTENANCE PROJECT

2.Double-click on the CustomerMaintenanceProject.msi file to start the installation.

The Windows Installer service prepares the user’s machine for the installation. Then, the Welcome page of the Setup wizard is displayed.

3.Click on the Next button to continue.

The Select Installation Folder page is displayed.

4.Browse for the location where you want to install the application by clicking on the Browse button.

5.Select the Everyone radio button if you want to enable all the users who log on to the machine to access the application.

By default, the Just me radio button is selected.

6.Click on the Next button to continue.

The Confirm Installation page is displayed.

7.Click on the Next button to start the installation.

A progress bar shows the progress of the installation process. When the installation process is complete, the Installation Complete page is displayed.

8.Click on the Close button to complete the installation.

The CustomerMaintenanceProject.exe file is created in the specified folder.

9.Double-click the CustomerMaintenanceProject.exe file to run the Windows application.

Having tested the application, you can distribute the application to your customer.

Merge Module

In addition to a CAB or Setup project, you can create a Merge Module project by using the templates provided by Visual Studio .NET. A Merge Module project is used to combine the application files, resource files, registry files, and Setup files in a single package.

You use the Merge Modules for projects that can be shared across applications. This implies that the components used to set up a Merge Modules project can be

DEPLOYING A WINDOWS APPLICATION

Chapter 12

275

 

 

 

 

shared for multiple Merge Module projects. For example, consider a situation in which you need to distribute two applications on a user’s computer. In this case, you can have a common set of setup components for both the applications.Therefore, the Merge Module projects are similar to the dynamic link library (.dll) files, which allow applications to share the code.

In addition to the setup components, you can create any component as a Merge Module that needs to be shared across multiple applications. For example, if a resource is used in more than one application, you can deploy the resource as a Merge Module and can then reuse the resource file for multiple applications. However, you cannot install a Merge Module alone. It can be added to the MSI files that you have created in the previous section.

TIP

You can add a Merge Module component while creating a MSI file. In addition, the merge module component can be added after the MSI files are created.

Another advantage of creating a Merge Module project is that the project recognizes all the dependencies for a component and tracks the versions of the component. This prevents the user from installing the incorrect version of the component. To further avoid any version problem while installing a component, you must create a Merge Module project that contains the dependencies of the component.

You will now learn how to create a Merge Module project. You can create a Merge Module project similar to the way you created the Setup Project.However, instead of selecting the Setup Project option in the Add New Project dialog box, select the Merge Module option. After performing the required steps, build the Merge Module project to create a .msm file. Figure 12-11 shows the file system editor of the Merge Module project.

276 Project 1 CREATING A CUSTOMER MAINTENANCE PROJECT

FIGURE 12-11 The file system editor of the Merge Module project

As discussed earlier, to deploy the .msm file, you need to merge the file with a Windows Installer (.msi) file. The MSI file that contains a Merge Module component also stores information about the version of the component.

While you install the application, the Windows Installer service adds the version information to a Windows Installer database that enables multiple applications to use a component. If you uninstall any one application, the Windows Installer database ensures that the corresponding component is not uninstalled.

In the preceding sections, you looked at creating various deployment projects by using the templates provided by Visual Studio .NET. However, you can create these deployment projects by using the Setup wizard.

The Setup Wizard

The Setup wizard is used to create various deployment projects. You can now create a deployment project by using the Setup wizard. To access the Setup wizard, select the Setup Wizard option in the Add New Project dialog box.The Welcome

DEPLOYING A WINDOWS APPLICATION

Chapter 12

277

 

 

 

 

page of the Setup wizard is displayed. To create the deployment project by using the wizard, perform the following steps.

1.On the Welcome page of the wizard, click on the Next button to start the Setup wizard.

The Choose a project type page is displayed.

2.Click on the radio button to create the type of deployment project.

The wizard provides you with an option to create a Setup project for a Windows application, a Setup project for a Web application, a Merge Module for a Windows Installer, and a downloadable CAB file.

3.Click on the Next button to display the Choose project outputs to include page.

4.In the Which project output groups do you want to include? text box, check the file options that you want to include in your deployment project, and click on the Next button.

The Choose files to include page is displayed. This page allows you to add any additional file other than the files that you added in Step 4, such as .txt or .htm files. You can add a file by clicking on the Add button. Because adding additional files is optional, you may choose to proceed further without adding any additional files.

5.Click on the Next button to display the Create Project page.

The Create Project page displays the summary of the information that you have specified in the Setup wizard. Figure 12-12 displays the summary of the information specified in the Setup wizard.

6.To create the project, click on the Finish button on the Create Project page.