6.7 File System ViewAll applications need to copy one or more files onto the target computer. Visual Studio .NET's Setup project File System view lets you choose which files will be installed and where they will go. Figure 6-12 shows a typical File System view in a normal Setup project. (Web Setup projects have different defaults—they just have a single folder labeled Web Application Folder.) Figure 6-12. File System viewThe tree on the left of the view represents various folders on the target machine. Folders are never referred to by their exact path, as hardcoding paths into installers is bad practice. System directories tend to be in different places from one machine to the next. (For example, the Windows directory might be C:\WINNT or D:\WINDOWS.) Forcing a particular installation path for the application is also bad practice—you should let users choose where to put the program. The exact path for all folders will therefore be determined during installation. Visual Studio .NET therefore supports a number of predefined abstract folders. For example, the Application Folder shown in Figure 6-12 represents the folder chosen by the user when installing the application. (By default, this is typically, but not necessarily, C:\Program Files\Company Name\Application Name.) You would usually put your program's executable files in here. For Web Setup projects, you will instead see a Web Application Folder, which represents the virtual directory into which the application is installed. You can add other folders by choosing from the Add Special Folder submenu of the "File system on target machine' node"s context menu. Most of the standard system directories are supported. Table 6-3 describes each special folder.
Having decided which directories you wish to populate during installation, you must tell Visual Studio .NET what files it should place in those directories. You do this by selecting the folder and then selecting Add from the context menu. As Figure 6-13 shows, you have several choices. You can add a new subdirectory with Folder. You can install any file you like. The Assembly item lets you install a .NET component and get Visual Studio .NET to automatically determine which other components it depends upon and install those too. Project Output lets you install components built by other projects in the same solution as your Setup project. Figure 6-13. Populating folders6.7.1 Adding Project OutputWhatever else you choose to install on the target machine, you will almost certainly want to copy your program's executable code. The way to do this is to add a Project Output item to the appropriate folder. (For a normal application, this will be the Application Folder. For a web application, it will usually be the Web Application Folder.)
When you select Add Project Output... from a folder context menu (as shown in Figure 6-13) the Add Project Output Group dialog (Figure 6-14) will appear. This lets you choose the project whose output you would like to include (from the Project: combo box). It also allows you to select which particular items you would like to install—projects generate several outputs, but you don't necessarily want to install all of them. Figure 6-14. Adding project outputFor nonweb applications, you will normally want just the Primary Output group (see Table 6-4). The Primary Output is the main file that the project builds. This will usually be either a DLL or an EXE file, depending on the project type. For web applications, you will also want to select Content Files—this includes .aspx pages and any graphics.
Sometimes, you may wish to include some but not all of the files in an output group. For example, a web application may contain pages that are for debugging purposes and that should not be deployed on a live server. Visual Studio .NET allows you to leave out certain files when installing an output group by setting the output item's ExcludeFilter property. You may add multiple filters with this property. Each filter can be either a specific file or a filename containing wildcards, as Figure 6-15 shows. Figure 6-15. Setting an ExcludeFilter6.7.1.1 COM registrationIf you have a project that builds a COM component, you will need to make sure that the component is registered correctly when it is installed. You can ensure this by setting the project output's Register property. The Properties page allows you to select the Register property's value from a listbox; the available options are vsdrpNoRegister, vsdrpCOM, vsdrpCOMRelativePath, vsdrpCOMSelfReg, and vsdrpFont. (vsdrpFont is used for installing new fonts and is not used for COM registration.) To install a COM component in the usual way, making it available to any application on the machine, select the vsdrpCOM option. Isolated registration is also supported—you can install the component in such a way that it will be accessible only to your application, and not to the whole system. For this, you should choose the vsdrpCOMRelativePath option. (This works only when the target system is Windows 2000 or later.) vsdrpCOM and vsdrpCOMRelativePath allow Windows Installer to perform all registry updates. Visual Studio .NET will make sure that all of the appropriate registry configuration information is stored in the Windows Installer file. However, it is sometimes vitally important that a component be allowed to do its own registration. (For example, it may do more in its DllRegisterServer function than just updating the registry.) In this case, you should choose the vsdrpCOMSelfReg option. As a rule, though, it is better not to use vsdrpCOMSelfReg if possible—you should avoid creating COM components that require it, because Windows Installer cannot robustly repair or roll back installations that use this technique, as it doesn't know what configuration changes are made by the component. 6.7.2 Adding FilesIf you wish to install a specific file that is not a part of a project, you can do this with the Add File... option from the folder context menu. You would normally do this only with isolated files such as bitmaps or documents. You should avoid using this option to install binaries—you should instead add the merge module for the binary component to the project.
6.7.3 Adding AssembliesIf you want to add a .NET assembly for which you don't have a merge module, you can at least get Visual Studio .NET to do automatic dependency analysis for the component. Instead of adding it as a file, select the Add Assembly option from the folder context menu. Visual Studio will present the Component Selector dialog. (This is the same dialog used when adding a reference to a project, except it shows only the .NET tab.) You can select assemblies that your project requires from this list. Most of the time you will not need to do this—if you add a project reference to the component in the usual way, Visual Studio .NET will detect the dependency automatically, and you will not need to add it manually. You would need to add it this way only if the reference was not automatically detectable (e.g., you are using the assembly entirely through the .NET Reflection API). 6.7.4 Adding Merge ModulesIf your application depends on another component, you should include the merge module for that component in your installer. Strictly speaking, merge modules are not added to the File System view. This is because merge modules are self-contained—they know where the files they contain need to be installed. You can add a merge module to the project explicitly with the Add Merge Module... option of the Setup project's context menu. This displays a normal File Open dialog that lets you choose the merge module to include. By default, it will show you the contents of C:\Program Files\Common\Merge Modules, which is where Visual Studio .NET installs redistributable merge modules. This option is not available in a Merge Module Setup project, because you cannot nest a merge module inside another. However, if your component does depend on another component, you can add a reference to its merge module with the project context menu's Add Merge Module Reference... item. The result of this will be that when your merge module is added to an application, Visual Studio .NET will automatically add in all the other merge modules that yours depends on. |