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

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

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

This page intentionally left blank

 

 

Y

 

L

 

F

 

M

 

A

 

E

 

T

 

 

Team-Fly®

Chapter 12

Deploying a

Windows

Application

260 Project 1 CREATING A CUSTOMER MAINTENANCE PROJECT

In the preceding chapters, you created the Customer Maintenance project for CareKar, Inc. However, until now, you have not deployed the project at the client site. Visual Studio .NET provides you with the functionality to deploy the application that you have created on any other computer. You can also distribute your application on another computer in the form of a program that can be easily installed on the computer. In this chapter, you will learn to deploy a Windows

application.

Introduction to Deploying a Windows Application

In real-life situations, you often need to execute a Windows application that you have created on a computer other than the computer on which you created the application. This is called deploying a Windows application. Deploying a Windows application in Visual Studio .NET can be as simple as compiling the application in the form of an .exe file. You can then execute the application by copying the

.exe file of the application on another computer.

However, for huge applications, like the one that you have created for CareKar, Inc., compiling the application as an .exe file may not guarantee the successful deployment of the application. In such cases, you need to create an installation program to deploy your application on another computer. The user can then run the installation program that copies the installation files to the user’s computer. In addition, the user is not required to explicitly make changes to the registry of the computer. The installation program modifies the registry, enabling the application to run on the user’s computer.

To execute an application in Visual Studio .NET, the application is first converted to managed code that is managed by the CLR (common language runtime). To do so, the installation program makes the CLR files, which are required for the execution of the application, available to the application.

DEPLOYING A WINDOWS APPLICATION

Chapter 12

261

 

 

 

 

The process of deploying an application as an installable program on the user’s machine requires you to decide on the location where you need to deploy the application. In addition, you need to identify the method by which the application is to be deployed. To create an installation program for your application, you can use various deployment projects available in Visual Studio .NET, which are discussed in the following section.

Deployment Projects Available in Visual Studio .NET

A deployment project in Visual Studio .NET is a project that enables you to create an installation program to ensure a successful deployment of your application on another computer. Figure 12-1 displays various deployment projects provided by Visual Studio .NET.

FIGURE 12-1 Various deployment projects in Visual Studio .NET

You can choose the type of deployment project to be used depending on the type of application that you create.

262 Project 1 CREATING A CUSTOMER MAINTENANCE PROJECT

The CAB Project

The simplest way to deploy a Windows application is to convert the application to a CAB (cabinet) file. A CAB file is a compressed form of your project. This implies that a CAB file compresses the application into smaller files that occupy less memory on the user’s computer. Therefore, converting an application to a CAB project enables the user to store the application in a compressed and organized manner. In addition, the CAB files that you create for your project can be easily transported and deployed on the user’s machine.

A CAB file can be used to package the ActiveX controls. Packaging an ActiveX control involves signing the ActiveX control or the application that contains the control. This process is called Authenticode signing. This enables the user to identify the source of the application and verify its authenticity. In addition, users can easily download and then install these files on their machines. You will learn about packaging Web applications that can be downloaded from a Web server in Chapter 26, “Deploying the Application.”

To enable you to convert your application into a CAB file, Visual Studio .NET provides the Cab Project template. To access the Cab Project template, 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.In the Project Types: pane of the Add New Project dialog box, select the Setup and Deployment Projects option.

Various options of deployment projects available in Visual Studio .NET are displayed in the Templates: pane.

4.Select the Cab Project option.

Figure 12-2 shows the Cab Project option.

DEPLOYING A WINDOWS APPLICATION

Chapter 12

 

263

 

 

 

 

 

 

FIGURE 12-2 The Cab Project option in the Add New Project dialog box

5. In the Name: text box, type the name of the Cab Project as Customer-

MaintenanceCabProject.

6.Browse for the location where you want to save CustomerMaintenanceCabProject by using the Browse button.

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

CustomerMaintenanceCabProject is added to the Solution Explorer window. Figure 12-3 shows CustomerMaintenanceCabProject added to the Solution Explorer window.

264 Project 1 CREATING A CUSTOMER MAINTENANCE PROJECT

FIGURE 12-3 CustomerMaintenanceCabProject in the Solution Explorer window

The Properties window of the CustomerMaintenanceCabProject project displays information about the project,such as the name, version number, and Web dependencies of the project.

TIP

Visual Studio .NET does not specify any Web dependencies of the CAB projects. However, you can create references to any Web dependencies by changing the Web dependencies property of the CAB project. If Web dependencies property is set, all dependencies are automatically downloaded and installed when the CAB file is run.

You can also implement Authenticode signing by checking the Authenticode signing: check box in CustomerMaintenanceCabProject Property Pages. To access CustomerMaintenanceCabProject Property Pages, perform the following step:

1.Click on the View menu and select the Property Pages option. Alternatively, you can press the Shift+F4 keys.

CustomerMaintenanceCabProject Property Pages is displayed. Figure 12-4 shows CustomerMaintenanceCabProject Property Pages.

DEPLOYING A WINDOWS APPLICATION

Chapter 12

265

 

 

 

 

FIGURE 12-4 CustomerMaintenanceCabProject Property Pages

You can also specify the amount by which you want to compress the application in the properties of the CAB project. For example, if you compress an application by a higher amount, the file creation process takes more time compared to compressing a file by lower amounts. However, a file with higher compression level takes less time to download. In addition, the properties of a CAB project allow you to specify the location where you want to store the executable files.

However, the CustomerMaintenanceCabProject project that you have created does not contain the application files. To add the application files to the CAB project, perform the following steps:

1.Right-click on the CustomerMaintenanceCabProject project in the Solution Explorer window.

2.In the displayed list, point to the Add option. The displayed list contains the following options.

Project Output. The Project Output option displays the Add Project Output Group dialog box that provides several options of files that you can add to the CAB project. Table 12-1 displays the file options in the Add Project Output Group dialog box.

File. The File option enables you to add an arbitrary file other than the files listed in Table 12-1 of the CAB project.

266

Project 1

CREATING A CUSTOMER MAINTENANCE PROJECT

 

 

 

 

 

 

Table 12-1 File Options in the Add Project Output Group dialog box

 

 

 

 

 

 

File Options

Description

 

 

 

 

 

 

Documentation Files

Documentation Files contain the documentation of the project.

 

 

Primary Output

The Primary Output files contain the executable files built by the

 

 

 

 

project.

 

 

Localized Resources

The Localized Resources files contain the assembly information

 

 

 

 

about the resources used in the project.

 

 

Debug Symbols

The Debug Symbols files contain the debugging files required for

 

 

 

 

the project.

 

 

Content Files

Content Files contain all the content files used in the project.

 

 

Source Files

Source Files contain all the source files used in the project.

 

 

 

 

 

After learning about the types of files that Visual Studio .NET allows you to add to the CAB project, you can continue with the steps to add files to the CustomerMaintenanceCabProject project that you have created.

3.Select the Project Output option.

The Add Project Output Group dialog box is displayed. The name of the project is displayed in the Project: list box.

4.Select the Primary Output option from the file options in the Add Project Output Group dialog box.

TIP

The Primary Output option is a mandatory option. However, you may choose to select any other option to be deployed along with the application.

5.Click on the OK button to close the Add Project Output Group dialog box.

The Primary Output option is displayed in the Solution Explorer window. You can view the file name and the path of the executable file in the Properties window of the Primary Output option.

DEPLOYING A WINDOWS APPLICATION

Chapter 12

 

267

 

 

 

 

 

 

6.Select the Primary Output option in the Solution Explorer window to display the Properties window.

7.Click the ellipsis button of the Outputs property.

8.The Outputs dialog box is displayed, which contains information about the executable file for the Customer Maintenance project.

Figure 12-5 displays the Outputs dialog box.

9.Build the project by clicking on the F5 key.

Alternatively, you can select the Start option on the Debug menu.

FIGURE 12-5 The Outputs dialog box

To create the executable file, you need to build the CustomerMaintenanceCabProject project, as described in the previous Step 9.

Building the project creates an executable file in the location specified in the Outputs dialog box. The executable file, along with an .osd file, is created in the form of a compressed file. To access these files, you can unzip the CustomerMaintenanceCabProject.CAB file. The .osd file contains the information about the CustomerMaintenanceCabProject.CAB file in the XML format. Figure 12-6 shows the contents of the .osd file.