Friday, May 26, 2006

WiX: Changing entry name in ProgramMenuFolder in the runtime

Recently I was developing installation package using WiX toolset. And encountered interesting problem.


Installation package after installing application, also installs shortcuts into “Start” program menu, ( in WiX constant for it is “ProgramMenuFolder“ ).

The task was to set the name of Programs sub-entry with specific ( dynamic name ). This name is generated during installation time.

So, how to resolve?

It appears that if you write

<Directory Id="ProgramMenuFolder" Name="PMenu" LongName="Programs">
<Directory Id="ProgramMenuDir" Name='Comp' LongName="Full Company Name">
</Directory>
</Directory>

you expose “ProgramMenuDir” as public property, which you can change.

Okay, the question arises how and when this property should be changed, so that installer used new value for creating the Programs menu sub-entry?

To set property value we can use custom action

<CustomAction Id="DIRCA_SETPROGRAMFOLDER" Return="check" Property="ProgramMenuDir"

Value="[ProgramMenuFolder]Company Title - [PUBLIC_PROPERTY]"></CustomAction>

Values in square brackets correspond to names of properties defined during installation. Square bracket notation means

[PROPERTY1] – take value of property with name “PROPERTY1”.

Good, we have custom action, that changes the property. When should it execute is another question?

Properties that are used as directory names are finally set during CostFinalize process, so to change the values of these properties we have

to launch our custom action before CostFinalize. Piece of cake!

<InstallUISequence>

<Custom Action="DIRCA_SETPROGRAMFOLDER" Before="CostFinalize"></Custom>

</InstallUISequence>

<InstallExecuteSequence>

<Custom Action="DIRCA_SETPROGRAMFOLDER" Before="CostFinalize"></Custom>

</InstallExecuteSequence>

Now, after installer successfully finished we have nice and custom entry in ProgramMenuFolder.

1 comment:

  1. Great post! Saved me a couple of hours of investigation. Thanks!

    ReplyDelete