Obtaining generated ProductCode as a variable in Wix

旧巷老猫 提交于 2019-12-24 03:30:00

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!