问题
In our product we use Product Id="*"
in Wix to tell it to generate a new product code for every new build. We now have a requirement during install time to record the product code of the MSI being installed into one of our registry keys. We could infer the product code at runtime by looping through entries in the "Uninstall" registry keys looking for our product name and version, but it would be cleaner to directly record this information at install time.
Is there a way for Wix to tell me what ProductCode
it has generated so that I can add it as a variable to a RegistryValue
Wix element?
I'm guessing there isn't, so I tried using a <?define?>
to set a variable to all question marks "????????-????-????-????-????????????"
and used this variable in the Product
element as well as the RegistryValue
element. This works for the Product
element ok, it continues to generate a new GUID, but in the RegistryValue
element this variable is not expanded at compile time, meaning the registry key simply gets added with all question marks.
Is there any pure Wix way to achieve what I want? I could generate the ProductCode
outside of Wix and have the Wix elements use this as an environment variable, but this adds an extra level of complexity to the build process - something else that could break. I would like it if I could do this purely with Wix.
回答1:
The product code is always available as a property, no matter what you put into the @ProductCode
. So, the following should work for your case:
<RegistryKey Root="HKLM" Key="My Product">
<RegistryValue Name="TheProductCode" Type="string" Value="[ProductCode]" KeyPath="yes" />
</RegistryKey>
Besides, it can be put not only in the registry value, but the registry key name:
<RegistryKey Root="HKLM" Key="$(var.RegistryRoot)\[ProductCode]">
...
</RegistryKey>
来源:https://stackoverflow.com/questions/18884019/obtaining-generated-productcode-as-a-variable-in-wix