Building an MSI File: Visual Studio and Orca - Building a Package
(Page 2 of 6 )
The first package you build is a simple one—this is the “Hello World” program’s equivalent in the installation context. You’ll install Notepad (NOTEPAD.EXE) and a text file, together with a shortcut to run the installed Notepad against the text file. Note that this project is supplied with the book, so you can build it yourself or use the one provided.
You start by running VS and choosing the New Project from the File menu, selecting Setup and Deployment Project, and then Setup Project. Once the wizard has completed, select the Project icon in the Solution Explorer. The Edit menu has drop-down choices for View -> Editor -> File System. When you’re in this File System view, you can then select Application Folder. Then you can right-click in the file pane and select Add, then File. Add NOTEPAD.EXE and SomeTextFile.txt in that pane. Because you’ll need a shortcut to NOTEPAD.EXE for the Programs menu, right-click NOTEPAD.EXE in the file pane that you just added it to, and choose Create Shortcut. At this point you should see something like Figure 2-1. Notice that this view also shows the Properties window for the Application Folder, where ProgramFilesFolder, Manufacturer, and ProductName are enclosed in square brackets. These are three standard Windows Installer properties. You’ll see more of these later because properties are the variables that drive the behavior of an installation. For now the important thing to know is that the value of [ProgramFilesFolder] is resolved when the installation runs and is replaced with the Program Files path on the system. Those square brackets mean that the identifier they contain is a Windows Installer property.

Figure 2-1. VS's Application folder with shortcut
You need the shortcut to Notepad for the User’s Programs Menu, so right-click that shortcut and select Cut. Then right-click the User’s Programs Menu item, select Add -> Folder to add a folder and a subfolder (I called it Phil and TryNotepad), then use Paste to get the shortcut into the pane. You’ll see something like Figure 2-1.
Before you do a build, right-click the Project in the Solution Explorer and set the build properties to package files “In setup file.” Options are here for bootstrappers (in other words, making sure that the Windows Installer engine is installed on the target system), but you’ll just be building the installer package, an MSI file. See Figure 2-2 for an example of the property pages for the build.

Figure 2-2. VS's build options
Now if you do a build it should create an installer package: an MSI file containing everything needed to install your Notepad application. You can now double-click the package and the installation starts. After the Welcome screen, you see a Select Installation folder that’s got some notable features (see Figure 2-3):

Figure 2-3 Selecting the installation folder
- The installer has resolved the ProgramFilesFolder property and the Folder box shows the actual path on the target system. This is a key feature of Windows Installer properties—not so much that they are resolved but that you can use them in square brackets in places such as folder names and Registry entries. I should point out that this folder isn’t always C:\Program Files, which is why Windows Installer supplies a variable property.
- The dialog wants to know whether you want to install this application for Just me or for Everyone. In other words, should this be installed for the current user or for all users of the system? This choice affects an important Windows Installer property that you can control—the ALLUSERS property you’ll look at later.
Select Everyone and continue. The installation should complete normally, and the Start Menu should now have the shortcut to initiate Notepad. You can uninstall the product in the usual ways via Add/Remove Programs, or by right-clicking the package and selecting Uninstall. However, you’re going to look at the content of the package, so after you’ve installed Orca, right-click the package and select Edit with Orca. What you see is a screen like Figure 2-4, where Orca shows each installer table in the left pane and the rows and columns of each table on the right. (Figure 2-9 shows a view with more tables shown.) In the case of Figure 2-4, Orca is showing the File table because it’s a useful place to start dissecting a package.

Figure 2-4. The File table
Before you go any further, the tables and their contents, including the details of each table and column, are documented in the Windows Installer section of the Platform SDK. I’m generally not going to repeat all that detail; I’ll just point out how the tables work and fit together so that you can make more sense of the documentation.
Notice that there is a row for each file you’re installing, and that each row has the name of a file in the FileName column. If you hadn’t guessed from the format, the file name is shown in short file name and long file name format separated by a vertical bar. Perhaps more interestingly, the File table shows the version for code files in the Version column (which appears only if the file has a version resource). If you were thinking that Windows Installer uses this version value to decide whether to replace older versions on the target system, you’re right, and you’ll be using this value when you get to Chapter 6, which describes updating products.
An important item in the File table is the Component_ column. A Windows Installer Component is the key unit of an installation. There is a component reference at almost every place in the package where something is going to be installed onto the client system. VS has generated two components in the File table, one for NOTEPAD.EXE and one for the text file. If you’ve installed something and selected a “Custom” install, you’re probably used to the idea of a list of features that can be selected or deselected for installation. The way this works in Windows Installer is that a feature consists of one or more components. In fact, if you look at Figure 2-5 you see the FeatureComponents table, which is where components get mapped to their owning feature. Notice that VS generates only one feature, called DefaultFeature. This is one of the limitations of VS: It has no capability to organize an installation into more than one feature. You also see more than just the two components in the File table here. It turns out that VS wants to be sure that the Program Menu folders get removed at uninstall time. It adds a component and some entries in the RemoveFile table to make sure that the Program Menu subfolders get deleted, and it creates a component because most activities done during an installation require an associated component. VS also creates a component to deal with some Registry entries it might create (more on this later in this chapter).

Figure 2-5. The Feature Components table
This is from The Definitive Guide to Windows Installer, by Phil Wilson, (Apress, ISBN: 1590592972). Check it out at your favorite bookstore today. Buy this book now. |
Next: A First Look at Shortcuts >>
More Visual Basic.NET Articles
More By Apress Publishing