This action might not be possible to undo. Are you sure you want to continue?
Yesterday you learned how to create Windows Forms applications. Today, you learn how to create a setup project that deploys a Windows Forms application to an end user's machine. If you're familiar with the Setup project type in Visual Basic 6, you'll be shocked and amazed at how easy and reliable it is to create setup projects in .NET. Today, you learn how to Create a Windows Installer package using Visual Studio .NET Create custom setup actions in installer packages Create a license agreement custom dialog Deploy the .NET Framework with your application
Introduction to Application Deployment
Deploying an application always seems like it's such a simple process to an end user. All the end user needs to do is double-click Setup.exe and the program he's trying to install works like magic and installs the files needed for the application. As a developer, you know that creating deployment projects with the tools provided by Microsoft has been a nightmare. Using Visual Basic 6 Setup and Deployment Wizard to deploy forms-based applications was a frightening thought. When an installation was complete on a target machine, you had to cross your fingers, and pray that when the machine rebooted there would be no blue screen of death, and that some core operating system file would not be accidentally overwritten by your installation package. This opened up the market for third-party deployment applications, for which most companies simply give in and pay big dollars. With the advent of Visual Studio .NET, there are no longer issues with deploying applications using the tools provided by Microsoft. It's easy to understand why deploying applications was so difficult before .NET. All components and applications on a machine needed to be registered in the Windows Registry. Any time the Registry is involved, there are going to be complications. With .NET, the Registry goes away. There's no need to register an application or component to make it work. The .NET Framework provides the runtime that all .NET applications need to run. So, if the .NET Framework is installed on the machine, your application runs without needing any extra handling.
This is a huge feature of .NET. The fact that you can literally copy a folder that contains an application from machine A to machine B, and just be able to run, saves a lot of configuration and deployment headaches. In addition to the core technology in .NET making the deployment of applications a snap, the actual installation technology has improved as the operating systems have improved. The Windows Installer technology is responsible for handling installation services in Windows. Windows Installer files have an .msi extension. When I refer to an MSI package, it's the same as a Windows Installer file.
Introduction to the Microsoft Windows Installer Service
The Windows Installer is the technology behind handling all setup and deployment in Windows Me, Windows XP, Windows 2000, and Windows .NET Server. Windows Installer packages can also run on earlier versions of Windows, but the technology is built into the newer Windows version. Windows Installer packages are predefined databases that contain information about what must be installed on a deployment target. Whereas the Visual Basic 6 Setup and Deployment Wizard used script files to determine the order of each component and files that needed to be installed, a Windows Installer package contains information about what must be installed, not how it should be installed. The Installer service keeps track of every application that's installed on a computer, allowing you to uninstall, repair, or reinstall a package based on the state of the machine. This also gives you the ability to roll back installations. For example, if an installation is at 90% and the installation is canceled, all changes made to the computer are rolled back. The installation is not left in a flux state. Using the tools in Visual Studio .NET, you can create Windows Installer packages that set properties and conditions, create custom dialogs, handle user preference input, and even include a product registration with the installation package. If your organization uses Windows 2000 Server or Windows .NET Server, a technology called Group Policy is built into Active Directory. Using Group Policy, an administrator can define what Windows Installer packages each client machine should have, and the setup is automatic when a user logs in to her machine. This is taken to the next level with Active Directory. If you delete a file that was installed, and attempt to launch the application's executable, the Windows Installer service verifies that the file exists on the client machine. If it doesn't, it's retrieved from the server. You can also update version information on
The Deployment Projects node in Visual Studio . .NET Applications.NET provides templates for creating deployment projects. Using Microsoft Servers and Windows Installer provides a bulletproof mechanism for keeping applications current and working.1 displays the Deployment Projects node of the New Project dialog. Merge modules are a major feature in Windows Installer. Cab Project— Creates Internet-deployable cabinet (CAB) files. Understanding the Deployment Projects Templates Visual Studio . You learn about this project type on Day 6. In the New Project dialog. and you'll learn how to implement a merge module later today. Figure 4. "Deploying ASP.NET.assemblies and the Windows Installer server always checks for new versions on the server. which normally contains applications assemblies. Setup Wizard— A basic wizard that enables you to choose deployment options for a project. The following is a list of deployment project types: Setup Project— Creates an empty setup project that you can customize." Merge Module Project— Creates a merge module. Web Setup Project— Creates a setup project with options set for deploying Web applications. there is a Deployment Projects node that contains the available templates for creating deployment projects.
NET. right-click the InstallerTest solution name in the Solution Explorer. select the Setup and Deployment Projects node. and name it InstallerTest as shown in Figure 4. and select Add.Creating a Windows Installer Package The easiest way to create a new MSI package is from an existing application. .3. you need to create a new Windows Forms project. Open Visual Studio . you can add a deployment template to your solution. When the New Project dialog pops up. After the project is created.2. Add New Project from the contextual menu. and click the OK button to add the new project to your solution. and then Setup Project. Creating the InstallerTest application. To do so. To see this work. Change the name to InstallerTestSetup as shown inFigure 4. create a new Windows Forms Application project.
4. which is known as the File System Editor (FSE). The InstallerTest solution after adding a setup project. the files and directories created using the FSE are created on the target machine. your Solution Explorer and main window should look like Figure 4. During the installation of your MSI package. The navigation of the FSE is the same as using Windows Explorer: The left pane contains the . Everything that you need to create the setup project can be done with this designer. Using the FSE.Adding a new setup project to your solution. After the new project is created. You're now looking at the interface that you'll use to create the MSI package. you create virtual objects that are stored in the MSI package you create.
Figure 4. Setting Properties on the Installer Package The next step is to set properties on the installation project. Note that the project wasn't automatically added when you added the deployment project to your solution.5shows the Properties window after I customized it with my own information. In this case.6 demonstrates. it's your InstallerTest Windows Forms project. creating shortcuts. select the InstallerTestSetup project name in the Solution Explorer. such as creating directories. From the contextual menu. Adding the Application Output to the Installer Package Now that some properties are set. adding files. and specifying build options. select Add. .hierarchy of the directory. you must tell the Installer project what the primary output is to install. and what information is displayed in the Add/Remove Programs applet of Control Panel. The properties you set here define what information is displayed in dialogs during the setup. Each item in both panes has a contextual menu that pops up with a right-click. giving you action options to perform. and the right pane contains the details. right-click on Application Folder on the File System Editor. Setting properties in the InstallerTestSetup project. You must always add the files to be installed. To do so. as Figure 4. To add the InstallerTest application to this installer package. Do the same to your properties. and press the F4 key to get to the Properties window. Project Output.
8. Your application should look like Figure 4. By default.The Add Project Output menu selection. . the primary output has been added to the InstallerTestSetup project. When you select the Add Project Output option.7 shows The Add Project Output Group dialog. you're prompted with the Add Project Output Group dialog. as Figure 4. the active project in the solution is in the Project drop-down list. Click the OK button on the Add Project Output Group dialog box to add the InstallerTest application to this setup package. At this point.
or anything.9. Change the shortcut name to Installer Test. If you right-click on the primary output in the right pane of the File System Editor. you can drag it to the folders in the left pane of the File System Editor. shortcut. be it a file. will be added during the installation. you can see the available options for the output assembly. click the Create Shortcut menu item. File System Editor after creating a shortcut for the primary output. From the contextual menu. After you create the shortcut. Your File System Editor should now look like Figure 4.Solution after adding the primary output. Anything you add to the folders. .
Setting properties on a shortcut. you'll see some of the available properties that you can set. Change the Description property to My First Test Of Installing. such as file dependencies or version requirements for dependent applications Installing custom files based on user selections during setup Creating databases or other objects programmatically Launching applications when installation is complete To test this. If you right-click the shortcut.10 demonstrates. and select Properties from the contextual menu. . as Figure 4.Remember that the File System Editor is a virtual view of the target machine. Drag the shortcut to the User's Desktop node in the left pane. Some of the features are Associating a file extension with your application Adding Registry keys based on user input Setting launch conditions. specifying that Microsoft Word version 9. Creating Custom Actions One of the key features that deployment projects offer is the ability to create custom actions for your installation package. you're going to create a Registry key and a version launch condition.0 or greater is required by your application.
Add a key named TestKey. or dependency before installation starts.Creating a Registry Key To create a Registry key. change the Value property to Maximize. This is just an example of what you can do with a launch condition. You might specifically need the Word 9.0 is installed on the deployment target. right-click on TestKey and select New.0 type library to make sure that your Word Merge code doesn't crash. you can enable the user to modify the user preferences as needed. click the View main menu. the type libraries for Office aren't always compatible. you have complete control over what Registry keys you add to your application. In this step of setting up the test installer. After you add keys and values to the Registry. Registry . Right-click the HKEY_CURRENT_USER node and select Add Key from the contextual menu. application. After the key is added.NET Framework. you can access them using the classes in the . Name the new string value ScreenPref. In your application. but there are hundreds of reasons why this is a great feature. From this screen. The following list should give you some ideas: If you're doing any Microsoft Office automation. Using the Registry Editor is a great way to set default user preferences.You're now in the virtual Registry Editor. and then select Editor. String Value from the contextual menu. you're going to make sure that Microsoft Word version 9. . In the Properties window. Adding a Launch Condition Adding a launch condition forces the installer to check for the existence of a file.
If your application uses Active Directory. as demonstrated in Figure 4. When the Launch Condition Editor is open.NET Framework installed.0 or higher. such as Internet Explorer 5. .15 demonstrates. select Editor. To test this. your application won't run. he Launch Conditions menu selection. you can ensure that they're on the machine before installation. If the machine doesn't have the . Launch Conditions from the View menu. If you depend on a specific browser version. it will work only on Windows XP or greater. If you're using a specific version of Microsoft Data Access Components ( MDAC). right-click on the Requirements for Target Machine node and select Add File Launch Condition. so you need a launch condition to check this. you can stop the installation if that version does not exist on the machine. so you must check the OS version before installing.14. as Figure 4.
Notice the Depthproperty is changed to 2. Figure 4. you'll notice the Properties window appears. If you select this item. From this menu.NET Framework. and you can set the conditions for the file search. specific version launch conditions. That means I want the installer to search two levels deep inside the Program Files folder.Adding a file launch condition. and Windows Installer . and directory information for this search. you can create conditions for checking the existence of the . After you add the file launch condition. specific Registry settings. the longer the search will take to complete IIS settings. a new item named Search For File1 is placed under the Search Target Machine node.16 demonstrates how to add version information. The more depth you specify. filename. Take note of the other launch conditions.
Because I know that Word 9. MinVersion.0 file search to another file and set the properties accordingly if you want to attempt another search. and MaxVersion properties. I used my Windows Explorer to find WinWord.17demonstrates. as Figure 4. my install will succeed when I test it.Setting the Word Search launch conditions.0 is on my machine. . You should change the Word 9.exe and viewed its properties. To verify the FileName.
select Editor. as shown in Figure 4. . Condition1 has an Error property that you can set to prompt the user if the installation will fail. These could range from simple license agreement prompts to complex installation options. To complete the version and file search for Word. User Interface from the View menu to get the Dialog Editor.Filename and version information for MS Word. Change the Error property to a useful error message based on the file you're searching for. You can also set the Property property in the Word 9. and use thatProperty name as the Condition property for the launch condition. you need to change the Condition1 item that was added under the Launch Conditions node when you added the file search. To see what options are available.18.0 Search node to a friendlier name. Using Custom Dialogs During Installation The Dialog Editor enables you to add custom dialog options for the installation package.
19 that the standard dialog boxes already exist in the setup package.The User Interface menu selection. You can see in Figure 4. you can right-click the node that you want the dialog box to appear under and select Add Dialog. To add custom dialogs. .
NET integrated development environment (IDE). The license agreement dialog has a LicenseFile property that you can select to indicate what the license file is. you should right-click the License Agreement node. you don't need to add a license agreement. After you select Add Dialog from the contextual menu. My goal is to get you comfortable with the different available options.Standard dialog boxes are already added. The Add Dialog dialog box. From the Add Dialog dialog box. as Figure 4. This adds the default license agreement screen to your installation. The next step is to build the MSI package.20demonstrates. For this example. you are prompted with the Add Dialog dialog box. and must be included with the installation. When you add the custom dialog. select the Install . and select Move Up from the contextual menu. select the License Agreement dialog box. Within the Visual Studio . This file must be a rich text format (RTF) file. Because a license agreement should logically appear before the installation actually begins. You can manipulate the order in which all screens appear by moving them up or down. so you can just leave the LicenseFile property blank. it ends up as the last dialog in the node you added it to. Building the Application You've now completed the basics in building a solid installation package.
To build the package. Doing so builds the TestInstaller. Before you select Build Solution from the Build menu. If you view the results of the build in the Output window. Notice the various configurations you can set. You can also include an Authenticode certificate for your installation. select Build Solution from the Build menu. using the Install and Uninstall menu items is a good idea.21 is the properties dialog for the installer solution.msi. Build configuration properties. You'll learn how to factor that in during the next section. If any errors are encountered during the build. Figure 4. you're notified of them through the Task Window. right-click on the TestInstallerSetup project in the Solution Explorer and select Properties from the contextual menu. the 20MB redistribution package for the .exe file and it createsTestInstallerSetup. You're going to be brave and just build the whole solution. you can navigate to the folder where the MSI package was created to view the output. By default. and test it from the command line. . This guarantees the source of your installation if you need it to be trusted by a client machine.NET Framework isn't included in the output.22 is where the MSI output was put on my machine. This enables you to test the installation as you're creating it. If you're testing different launch conditions and dialogs.NET Framework is required to make this installation work. After the project is built. Figure 4.menu item from the Project menu. you'll notice a message that the .
and two other EXE files.23. the launch condition for the Windows Installer makes sure that the target machine has the correct Windows Installer version installed. So. double-click theTestInstallerSetup. The first screen you should see is shown in Figure 4. .msi file in the file system. You'll notice that there's an MSI package. Running the MSI Package Now you can run the MSI package you just built to view the dialogs and the behavior of the installation.exe file.exe andInstMsiW. which welcomes you to the setup for your project. a Setup. When you deploy an application.exe are version-specific Windows Installer setup packages.Browsing to the setup files. The files named InstMisA.
If you click Next.24shows the License Agreement dialog. Figure 4. . you'll see the custom dialog box you added that makes the user select I Agree in order to continue.The Welcome screen for TestInstallerSetup.
. and the setup will still be functional. you should see the single form of your application pop up. After the setup is complete. you'll see the Test Setup Installer as Figure 4. you should have a new shortcut on your desktop for the application. Just like that. Now open up the Control Panel. If you double-click the shortcut. you can delete the dialogs from the Dialog Editor. If you scroll down.The custom License Agreement dialog box. Finish the installation by clicking Next for each screen you're given. you have a complete installation package. and select the Add or Remove Programs icon. These are the default dialogs that always appear unless you explicitly delete them from the Dialogs Editor.25 shows. If you want an installation to occur with no user interaction.
.Your application in Add or Remove Programs.26. you'll see something like Figure 4. If you click the hyperlink that says Click Here for Support Information.
You're now prompted with the Add Module dialog that Figure 4. To find out how to add a merge module. They must be part of an MSI package. The beauty of merge modules is that they're independent installation components that contain all the necessary logic to successfully install. Merge Module from the Project main menu. launch conditions. Like the setup project you created earlier. you can create a merge module project with resources. File System Editor from the contextual menu.Adding Merge Modules to Your Setup Merge modules are another method of packaging a component for redistribution.27displays. Next. There's a Merge Module project template that you can use to create your own merge modules. . he Add Modules dialog box. or just as a mechanism of breaking apart a large installation. but they can't be installed on their own. select Add. or you can add a merge module to your setup project if it already exists. Merge modules are very useful for pre-packaging components that must be shared across multiple resources on a computer. dependencies. return to the InstallerTestSetup project and get to the File System Editor by right-clicking on the project name and selecting View. and custom actions.
the MSMakedEdit control's merge module will be included with the MSI package.In the C:\Program Files\Common Files\Merge Modules folder there are predefined merge modules for several components. If the installation of the merge module fails.msm as shown in Figure 4. Select themsmask32_X86_ENU.msm extension.27. it can be seen in your Solution Explorer. and it will install as part of your package. From your point of view. Notice that merge modules have an . the complete installation fails because the merge module is part of the package. it's just another component to include in your deployment package. After the file is selected. . When you build the application.