Deploying Windows Applications with Visual Studio.NET, Part 2
Part 1 of this series explained the different ways of deploying a Windows application with the .NET Framework and identified when to use which deployment option. It also demonstrated the configurations that are required to create an installer package. Part 2 examines the different editors that Visual Studio.NET provides and identifies the steps involved in using them.
As Part 1 showed, you can access six types of editors in Visual Studio .NET deployment projects through the View | Editors menu. These types are as follows:
- File System Editor—Adds files and shortcuts, such as Start menu items, to the installation package.
- Registry Editor—Manipulates Registry entries on the target computer.
- File Types Editor—Associates file extensions with applications; useful when your application uses custom file extensions and you want to associate a specific application with that file extension.
- User Interface Editor—Configures the dialogs that are shown during the installation.
- Custom Actions Editor—Starts external programs during installs and uninstalls.
- Launch Conditions Editor—Specifies the requirements for your application to be installed on the target computer.
Editors in Visual Studio .NET Deployment Projects
The following section takes an in-depth look at each of these editors, beginning with the File System Editor.
File System Editor
As its name suggests, the File System Editor allows you to add project output files, assemblies, and other files to the deployment project. By using this editor, you also can specify the directory location where these files will be installed on the end user's computer. You can open the File System Editor by selecting View->Editor->File System. The menu looks like Figure 1.
Figure 1: File System Editor Menu
By using any of the pre-defined folders displayed in Figure 1, you can choose a destination folder on a target computer without even having to know the actual path to that folder. The installer determines it from the virtual path during installation. Take a brief look at each of the pre-defined folders and their purposes:
- Application Folder—Application Folder is normally represented by the path [ProgramFilesFolder][Manufacturer]\[ProductName]. On English systems, the [ProgramFilesFolder] folder resolves to [Drive Name]\Program Files by default. The Manufacturer and ProductName directories take their names from the settings that you defined while setting the project properties. End users also can override these settings while installing the application.
- Global Assembly Cache folder—This folder allows you to specify the assemblies that must be installed as shared assemblies on the target computer.
- User's Desktop—This folder acts as a placeholder for files and folders that should appear on the end user's desktop. The default location for this folder is [DriveName]\Documents and Settings\[UserName]\Desktop. The username represents the name of the user who performs the installation.
- User's Programs Menu—This folder acts as a placeholder for entries that should appear on the programs group of the user. The default location for this folder is [DriveName]\Documents and Settings\[UserName]\Start Menu\Programs. The username represents the name of the user who performs the installation.
Apart from these folders, you also can add custom folders to the File System Editor from a pre-defined list. To display the list of special folders, right-click the File System on the Target Machine folder from the File System Editor and select Add Special Folder from the context menu.
Add Items to Special Folders
By using the File System Editor, you can add any of the following items to the special folders:
- Folder—Allows you to create a folder on the target machine in the specified directory
- Project Output—Allows you to specify where the output of one or more projects (.dll or .exe files) in the solution will be deployed on a target computer; also adds all the dependencies to the folder
- File—Allows you to deploy loose (zero compression) files to a target computer; very useful for deploying help files such as Readme.txt
- Assembly—Allows you to specify the assemblies that need to be added; adds all the referenced assemblies as well
Now that you've seen the different editors, configure your deployment project using the File System Editor. The following steps will use the FormattingApplication from the previous article. The first step in creating a setup is specifying which files you want to copy to the target computer:
- Add the primary output of the FormattingApplication to the installer using the Project | Add | Project Output menu. After selecting the Application Folder directory, select Primary Output in the Add Project Output Group dialog box. Pressing OK in the dialog box adds the primary output of the FormattingApplication project to the Application Folder of File System Editor. At the same time, it also adds the dependencies to the installer project.
- The FormattingApplication requires the .NET runtime, which it automatically adds to the installer project. As a result, the merge module for the .NET runtime dotnetfxredist_x86_enu.msm becomes visible in the Solution Explorer. This merge module includes all files for the .NET runtime. If the .NET runtime is not already installed on the target system, it will be installed along with your application.
This case requires that the .NET runtime be already present in the target machine. So, you'll exclude this file from the package. Select the file dotnetfxredist_x86_enu.msm and then set the Exclude property to true through its properties window.
- Now, add the additional folders and files. Right-click on Application Folder in the File System Editor and select Add->Folder. Name the created folder Support. This folder serves as a placeholder where you'll store all the supporting files for the application.
- Right-click on the Support folder and select Add | File, and then add the files readme.rtf, license.rtf, Readme.txt, and developer.bmp.
- Readme.txt should be available as an individual file so the end user can read that information before the installation. Make it a loose file (uncompressed) in the installer package. Select Readme.txt from the Support folder and select View->Properties Window. Change the PackageAs property to vsdpaLoose. This new setting overrides the setting vsdpaDefault, which packages the overall application.
- Add a provision that allows users to create a shortcut to the FormattingApplication in their desktops. As before, you'll need to add the shortcut to the User's Desktop folder. Right-click on Primary output from the FormattingApplication (Active) item in the Application folder and select Create Shortcut to Primary output from FormattingApplication (Active) from the context menu. Rename the shortcut Formatting Application. Drag and drop it in the User's Desktop folder. However, you want this shortcut to be installed only if the user wants to install it. Therefore, set the Condition property of the User's Desktop folder to SHORTCUTDEMO. This ensures that the shortcut will be installed only if this condition is set to true. Later in this article, you will create a dialog box where this property can be set.
- Make the program available from the Start->Programs menu by adding a shortcut to the User's Program Menu folder. Create another shortcut as before, renaming it Formatting Application. Drag and drop this shortcut in the User's Program's Menu folder. This time, you want this shortcut always to install so don't alter the Condition property.
Page 1 of 4