English 中文(简体)
MSI: How to install a component only if another component is not installed
原标题:

My application involves an optional component with shortcuts that supersede the shortcuts provided by the default install. I can t figure out how to make it only install the default shortcuts if this optional extra is not installed - or do I just need to give them both the same name and hope for the best? This needs to work through the Custom Installation tree as well as the regular buttons.

See the way it works is, if this extra selected on install, the Start Menu shortcuts for the main application have to instead point to this one, which will open the main one on its own when it needs to.

I m using InstallShield 2011 Professional.

EDIT: to clarify - I do have it as three components: main, main s shortcut, and addon with shortcut. I just don t know how to check if the addon one has been/is being installed in a way that I can put it in a condition for main s shortcut. Surely there s a variable for it? The documentation is very spartan.

问题回答

If I m understanding the question correctly, MAIN.EXE gets a shortcut unless MIDDLEMAN.EXE is getting installed. In which case MIDDLEMAN.EXE gets the shortcut.

This is an odd problem in that the existance of a component changes the definition of another component. Still, it can be done. The way I would do it is create a component for MIDDLEMAN.EXE and define it s shortcut. Create another component for MAIN.EXE and don t define it s shortcut.

Then write a custom action that runs in the execute sequence in immeadiate execution that runs after file costing. Have it check to see if MIDDLEMAN.EXE is not installed and not being installed. If this is true, have a write a temporary row to the ShortCut table to define the ShortCut for MAIN.EXE.

From there you can let MSI handle the rest without the need for deferred custom actions to handle servicing the shortcut.

Still, I can t help wondering if this couldn t be simplified by changing the design of the application. Basically you are trying to do dependency injection at the EXE level and it would be easier to accomplish this at the DLL level. In otherwords:

MAIN.EXE with ShortCut Optional DLL

The MAIN.EXE is always called but he will behave differently when Optional.DLL is present.

Assuming the default component is included in the installation, you can probably use a component condition for your extra component. You can then make sure that this extra component is installed only if the other component isn t, i.e. they become mutually exclusive. This will avoid any messing about with features that would make your Custom dialog much more complicated.

@Stephen: I can t see how you can avoid using features since only features are visible to the user in the GUI and hence allows the user to specify what to install?

I generally don t like this kind of solution since it doesn t validate according to internal consistency checkers for MSI files, but you can install the EXE in one component, and then have two components each with different shortcuts that you condition to be mutually exclusive. You then attach the customized shortcut component to the feature which triggers the custom shortcuts to be installed. The feature must be set visible in the GUI. The shortcuts must be non-advertised since they are in components without files. You may need to set the transient flag on the shortcut components to allow removal / addition of the right component for maintenance installs. Transient components have their component-conditions re-evaluated during maintenance installs to check if the conditions specified for them will trigger removal / addition.





相关问题
Correct place to install demostration projects?

With the new Windows 7 restrictions (well, new to Windows Vista anyways), we can no longer install demo projects to %ProgramFilesFolder%OurApplicationdemo since restricted users will not be able to ...

msi install program as startup

is it possible to install a program as a start up program using MSI installer?

Web Setup Project - Repair to overwrite files

I have a web setup project that creates an MSI. After first installation, my web site has some config files that can be modify manually. When triggering that MSI again, I am offered to repair the ...

Visual Studio Setup Projects: Cleartype

I use a Visual Studio Setup project to create an installer for some assemblies. However, the fonts the installer uses are always aliased, and don t appear to be the Windows standard. (source: ...

Implementing Update functionality

I want to implement the Update functionality for one of my .NET application. I saw that the Advanced Installer contains this functionality. Anybody recommends Advanced Installer for updating my ...

VS 2005 Setup - HKCU

I am trying to fix an existing application that uses a Visual Studio 2005 setup project. We are requiring it to work on limited user accounts for XP, our app is written in C# for .Net 2.0. It writes ...

热门标签