WiX: How can I set a property externally?

2019-04-06 08:29发布

In my WiX installer, I've got a property for a UserID that gets written to a registry key:

<Property Id='UserID' Value='123' />

<Directory Id='TARGETDIR' Name='SourceDir'>
    <Component Id='UserIDComponent' Guid='*'>
        <RegistryValue Root='HKCU' Key='Software\[Manufacturer]\[ProductName]' 
                       Type='integer' Value='[UserID]' Name='UserID' />
    </Component>

I'd like to set the value of that property to the User ID of the person downloading my installer on the fly. So when they go to download, I'll just create a copy of the base MSI that everyone gets, set the value of UserID to that of the person downloading the file, and that's what they download. It'll be the same installation package that everyone gets, but with the property custom set for them.

I can't seem to find any resources on how to set a WiX MSI property from an external source, though. How can I do this?

2条回答
叛逆
2楼-- · 2019-04-06 09:16

As far as I remember, you can indeed set properties from the "outside" - the property name has to be in all UPPERCASE to be recognized as a public property (don't ask me why....) and then you can set it like this:

msiexec /i C:\Example.msi PROPERTY=VALUE

e.g. in your case

msiexec /i C:\Example.msi USERID=somevalue

See the MSDN docs on using command line options with MSIEXEC

查看更多
劳资没心,怎么记你
3楼-- · 2019-04-06 09:25

Your options appear to be:-

(i) command line parameters on msiexec as per the other answer - fragile, not really an option if they are downloading and running it

(ii) attempt to hack the MSI file to insert the ID - a hack

(iii) launch MSBUILD to create a new MSI file on-demand on the server after modifying a copy of the WIX file to include their ID

(iv) pre-generate lots of MSI files with random IDs (GUIDs perhaps) in them and then associate those IDs with user IDs at download time in your database. Now provide a lookup service to map the random ID in the MSI file with the real user ID so that the program when it runs can find the user ID (or have a custom action that does this).

(v) create a custom action and use MsiGetProperty to get the filename of the installer - simply append the userID to the MSI file name - fragile hack

查看更多
登录 后发表回答