How to use properties to set the installation path

2019-09-17 09:26发布

问题:

I want to know how to set the installation path of the copied files by using properties. So, please let anyone explain the answer.

回答1:

If You are using a bootstrapper, You can define a variable like that:

<Variable Name="INSTALLFOLDER"
          bal:Overridable="yes"
          Type="string"
          Value="[ProgramFilesFolder]"/>

This variable has the ProgramFilesFolder as default, but it can be overwritten. You can set it either in Process.Start (when the bootstrapper is called by an EXE) as parameter or - if You have programmed Your own bootstrapper-GUI - You set the variable in the GUI-code.

In the MsiPackage You must set the variable into the MsiProperty INSTALLLOCATION, which You define in the Product.wxs of the MSI-project. Hope it helps You.

        <MsiPackage Id='SetupPackage'
                    SourceFile='.\Resources\Setup.msi'
                    Permanent='no'
                    Cache='yes'
                    DisplayInternalUI='no'
                    Vital='yes'
                    Compressed='yes'
                    EnableFeatureSelection='no'
                    DisplayName='MySetup'>
            <MsiProperty Name="INSTALLLOCATION"
                         Value="[INSTALLFOLDER]" />
        </MsiPackage>


回答2:

I know this may be too late to answer, but someone may find it useful.

Every Directory element defined in your Wix project can be accessed as a property using its Id:

For example if you have:

<Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLFOLDER" Name="My Directory" />
        </Directory>
    </Directory>
</Fragment>

You will have a property named INSTALLFOLDER and you will be able to access it from your custom actions.

Take a look to my answer here, that will give you the idea on how to pass the parameters to your custom action and use them.