WiX: How can I set a property externally?
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>开发者_JAVA技巧
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?
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
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
精彩评论