All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
23
Deploying
a Windows-Based
CHAPTER
23
Application
In this chapter, you will
• Plan and set up a web-based deployment
• Plan and set up a network deployment
• Learn the Windows Installer files and requirements
• Be able to register components and assemblies
• Recognize security policies
In this chapter, we will explore how you package and deploy an application, as it per-
tains to the Microsoft exam. You will need to know how to plan the deployment of a
Windows-based application from removable media, from the Web, and from a net-
work. You will also need to understand the Windows Installer requirements. One topic
of great concern to developers is how you install an application that allows components
and assemblies to be registered properly. Over the past few years, it has been difficult to
ensure that an uninstalled application actually removed all of its components. Users of-
ten have to “clean out” the Registry of entries left behind when an application is
dropped from the system. We will see, in this chapter, how that concern is addressed by
.NET.
If you haven’t had a chance to look at Chapter 6 in any detail, you should take the
time now. We will briefly review assemblies and the Global Assembly Cache (GAC) in
this chapter, but it has been covered in detail in Chapter 6. Security plays a big part in a
properly deployed application, and we will discuss security policies and look at configu-
ration files.
Review of Assemblies
An assembly is a group of files and resources that make up a single, executable unit. The
unit can be deployed, it has a version number, and it can be secured. An application is
made up of one or more assemblies.
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:44 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
23
Sn –k myAKeys.snk
This will create a file with public and private keys that will be used to give the assembly a
guaranteed unique name. Refer to Chapter 6 for more information on creating the
strong-name key file.
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:44 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
23
[assembly: AssemblyKeyFile("")]
to this:
[assembly: AssemblyKeyFile("myAKeys.snk")]
The compiler will now know to digitally sign the assembly using the keys found in the
.snk (strong-name key) file.
EXAM TIP You must recompile your program in order to apply the changes
made to the AssemblyInfo.cs file.
PART IV
EXAM TIP The cache can contain one or more versions of the same
assembly. This is called side-by-side versioning.
You can find the GAC in one of two locations, depending on the version of Windows:
The cache can be accessed using the GAC tool—gacutil.exe. This tool allows you
to view and change the contents of the GAC. In particular, it allows you to install assem-
blies into the cache or remove them from the cache. The syntax is as follows:
Table 23-1 displays the options available for the GAC tool.
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:45 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
23
Before we leave the discussion of assemblies, keep the following in mind. Shared
assemblies allow you to
Precompiling Assemblies
Instead of having your assemblies generated on the fly, you can run the Ngen.exe utility
and create a native image. This should cause the application to load faster, since the
work of compiling the code has been done in advance.
When an assembly is executed, the runtime searches for the native image (a file con-
taining compiled processor-specific code). If it is unable to find it, the runtime will look
for the JIT (just-in-time) compilation of the assembly.
EXAM TIP Remember that the reason to use Ngen.exe is to allow the
assembly to load and execute faster.
Not every application will benefit from using a precompiled assembly. You must do a
comparison between the JIT compiler and a precompiled assembly. The most benefit
will be seen in startup times and, in that case, a CPU-intensive startup would benefit
greatly from precompiling assemblies with Ngen.exe.
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:45 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
23
PART IV
about location and icons? All these questions can be answered by deploying your appli-
cation in one of the following ways:
• Setup project You can create a Windows Installer package that includes
setup files that will handle the actual installation. The setup files manage
your application files and resources and create an uninstall procedure to
remove the application.
• Web Setup project This is the same process as the Setup project, but you
can deploy your application from a web server.
• CAB project Remember the days of cabinet files? Well, they’re still around.
This is similar to having a ZIP file that contains all the necessary files and
resources. You can deploy it from an HTML page using a CAB project.
• Merge Module project This is the first step in creating a deployment project
that includes many different modules that must be brought together into one.
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:46 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
23
EXAM TIP Notice that the templates available from Setup and Deployment
Projects include Setup Project (which creates a Windows installer), Web
Setup Project (for deploying from a web server), Merge Module Project
(which accumulates modules), Setup Wizard, and Cab Project.
At this point you have two choices for a Setup project. You can either let the Setup
Wizard assist you through the process, or you can choose Setup Project and customize
the setup on your own (see Figure 23-1). We will start with the Setup Wizard here, and
then examine the more hands-on approach using Setup Project in the next section.
1. Choose Setup Wizard from the Templates in the Add New Project dialog box
(see Figure 23-1).
Figure 23-1
New project
templates
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:46 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
23
PART IV
3. The second wizard screen of the Setup Wizard (see the following illustration)
asks you to choose a project type—whether you are creating a Setup project
for a Windows or a web application. For this example, choose the Windows
application. This screen also asks whether you want to create a redistributable
package—a merge module or downloadable CAB file.
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:46 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
23
4. The third wizard screen asks which output groups you want to include in the
Setup project. Notice that you can select from documentation files, localized
resources, source files, and so forth.
5. Add any other files that need to be added to the Setup project in the fourth
wizard screen. Click the Add button and browse for your files. Then click Next.
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:47 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
23
PART IV
6. The last wizard screen is the summary window. It’s a good idea to read the
summary and make sure that you have included everything you need in the
project. The summary window will tell you if there were any errors and specifies
the output directory for the Setup project. If everything is okay, click Finish.
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:47 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
23
1. Select Setup Project from the Templates in the Add New Project dialog box
(see Figure 23-2). For this example, name the project “My College Installer”
and then click OK.
2. You will notice that the Solution Explorer has added your Setup project to the
list (see Figure 23-3). This figure also shows the properties of the new project.
You can set the author’s name, a description, manufacturer information, support
phone numbers, and version numbers, to name just a few of the properties.
EXAM TIP The name that you give the Setup project is important. This is the
name that will be displayed in project folders and the Add/Remove Programs
dialog box.
3. In Figure 23-4, you will see the format of the installer, and you can work with
the properties of the destination machine. In the File System on Target Machine
section, you can adjust the application folder, the user’s desktop, and the user’s
program menu as it pertains to your application.
Figure 23-2
Choose the Setup
Project template
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:48 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
23
PART IV
4. The next step is to add your application to the installer. Select your Setup
project in the Solution Explorer, right-click on it, and choose Add | Project
Output. You will see the Add Project Output Group dialog box shown in
the following illustration. Here you can specify the parts of the project that
will be added to the installer. For example, you can add documentation files,
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:48 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
All-In-One
screen / MCAD/MCSD
/ MCSD Visual
Visual
C#C#
.NET
.NET
Certification
Certification
All-in-One
All-in-One
Exam
Exam
Guide
Guide
/ Rempel
/ Rempel
& Lind
& Lind
/ 222443-6
/ 222443-6
/ Chapter
/ Chapter
23
23
localized resources, or, as shown in the illustration, the primary output, which
is the actual .DLL or .EXE built by the project.
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:48 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
23
Once the basic installer program is created, you can check the local file system for
your project directory, and you will see the files that have been created (see Figure 23-5).
The Windows Installer package has been created (My College Installer.msi),
along with the Setup application.
EXAM TIP Notice that our files are listed in a subdirectory called “Debug”.
You must ensure that you use a Release Build to create Setup projects. Use the
properties of the solution to set the Configuration to Release (see Figure 23-6).
Modifying Installers
There are a number of modifications you can make to your installer package after it’s
been created. You may want to create a shortcut on the user’s desktop or insert addi-
tional files in the package. This can all be done from Visual Studio .NET. The following
list explains three of the modifications you can make to the package:
• Add a shortcut to the user’s desktop Select the Primary output from
PART IV
<application> from the Solution Explorer. Find the “Primary output from
<application>” in the File System Editor, right-click on it, and choose Create
Shortcut To. This will create a shortcut (which you can rename). Drag the
new shortcut to the User’s Desktop folder.
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:49 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
23
• Add Registry entries for the application Select the installer project from the
Solution Explorer, right-click on it, and choose View | Registry. You will notice
that the left side of the screen changes, as shown in Figure 23-7. You can then
work with the Registry, and add keys and values. For example, you might want
to set an application property in the Registry called “Start-up mode.” By adjusting
the entry at this point, you can set the default value for the Registry and, in the
actual application, allow the user to change it.
• Set up custom installation windows Select the installer project from the
Solution Explorer, right-click on it, and choose View | User Interface. In the
User Interface tab (see Figure 23-8), choose the Start tab, right-click on it,
and make your choice. In the example shown in Figure 23-8, we asked for
Checkboxes from the Add Dialog dialog box. This will insert an additional,
customized dialog box into the installation procedure. Using this customized
dialog box, the user can make choices during the installation of the software.
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:49 PM
Color profile: Generic CMYK printer profile
All-In-One
Composite Default screen All-In-One
/ MCAD/MCSD
/ MCSD Visual
Visual
C#C#
.NET
.NET
Certification
Certification
All-in-One
All-in-One
Exam
Exam
Guide
Guide
/ Rempel
/ Rempel
& Lind
& Lind
/ 222443-6
/ 222443-6
/ Chapter
/ Chapter
23
23
PART IV
Figure 23-7 Adding Registry entries
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:50 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
23
EXAM TIP In order to deploy to a network solution, create the Web Setup
project and copy the installer to a server computer. The installer can then be
downloaded over a network.
Figure 23-9
Windows
Installer
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:50 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
23
PART IV
Creating a CAB Project
Creating a CAB project is perhaps the easiest of all solutions. A CAB project (a project
containing cabinet files) consists of a single, compressed file that contains all of the
Figure 23-11
Customized
dialog box
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:50 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
23
setup files. The project can be placed into an HTML page on an intranet or Internet site
and downloaded to the client computer from there. Once the user runs the setup pro-
gram, the CAB file’s contents are extracted and installed onto the user’s computer.
Here’s how you create a CAB project:
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:51 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
23
PART IV
EXAM TIP Creating a CAB project packages the files into a single, compressed
file with a .cab extension.
To create a Merge Module project, select Merge Module Project from the Setup and
Deployment Projects dialog box. To add a Merge Module project to an existing solution,
select File | Add | Existing Project from the menus.
EXAM TIP A merge module can also be used to deploy patches or new
versions of a component.
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:51 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
23
In order to ensure that your application meets with the requirements for the Win-
dows logo program, which allows you to distribute your application with “Designed for
Windows” attached to it, you must follow the requirements set forth in this web site:
http://www.microsoft.com/winlogo/software/.
Security Policies
In the next chapter, we will deal with security issues you should be aware of when prepar-
ing your application for user delivery. In short, policies are the set of rules that the runtime
uses when it loads your code. These policies can be configured in one of two ways:
The configuration tool can be run by selecting Start | Programs | Administrative Tools |
Microsoft .NET Framework Configuration. Figure 23-13 shows the .NET Framework
Configuration tool.
We will explore this tool in greater detail in the next chapter. Notice in Figure 23-13
that you can configure the assembly cache, manage assemblies, adjust remoting ser-
vices, manage applications, and configure security policies. If you select the latter, you
will see the Code Access Security Policy window shown in Figure 23-14. Stay tuned to
Chapter 24 for more information on security and security policies.
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:51 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
23
PART IV
Figure 23-13 The .NET Framework Configuration tool
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:52 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
23
Summary
Proper planning when deploying your application is crucial to its success. In this chapter,
we discussed the various methods of packaging your application:
• Windows Installer 2.0 files have the packages in a single .msi file, and they are
installed by running the Setup.exe program.
• CAB files have the packages in a single .cab file, and they can be downloaded
from a network server or an HTML page.
• The assemblies and executables can be provided in their original folders and
can be copied to the client machine using XCOPY or FTP.
We also looked at deployment of an application, which takes the packaged files and
sends them to a location for download or installation. Keep the advantages and disad-
vantages of each technique in mind when studying for the exam.
In the next chapter, we will look at security issues and expand on the discussion we
started in this chapter. We will also look at how you can optimize your final product.
Finally, we will wrap up all the loose ends that have not been covered yet, but that you
are liable to see one or two questions about on the exam. You’re almost there—hang in.
Test Questions
1. Which tool allows you to install an assembly into the GAC?
A. Ngen.exe
B. Mscorcfg.msc
C. Setup.exe
D. sn.exe
2. Which of the following accurately describes a strong named assembly?
A. A private assembly with a unique name within an application domain.
B. A private assembly with a unique name within a global domain.
C. A shared assembly with a unique name within an application domain.
D. A shared assembly with a unique name within a global domain.
3. Which template must be chosen from the Add New Project dialog box’s
Templates list in order to have an application downloaded from an IIS
(Internet Information Server) server?
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:52 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
23
PART IV
D. To ensure that all components register properly in the Registry.
6. Select two techniques for viewing the GAC.
A. .NET Configuration Viewer.
B. .NET Configuration tool.
C. gacutil.exe
D. gacview.exe
7. What can be configured using the .NET Configuration tool?
A. GAC cache.
B. Assemblies.
C. Security.
D. Policy levels.
E. All of the above.
F. None of the above.
8. Which of the following command-line entries would allow you to install an
assembly into the GAC?
A. gacutil /l myAssembly.exe
B. gacutil /i myAssembly.exe
C. gacutil /s myAssembly.exe
D. gacutil /h myAssembly.exe
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:53 PM
Color profile: Generic CMYK printer profile
Composite Default All-In-One
screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
23
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:53 PM
Color profile: Generic CMYK printer profile
All-In-One / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter
Composite Default screen
23
Test Answers
1. A.
2. B.
3. D.
4. C.
5. A.
PART IV
6. B, C.
7. E.
8. B.
9. D.
10. F.
11. C.
12. B.
13. A, B, D.
14. C.
15. A.
P:\010Comp\All-in-1\443-6\ch23.vp
Friday, August 23, 2002 5:05:53 PM