Anyway to create a custom MSBuild property in WIX wxs file?

*爱你&永不变心* 提交于 2019-12-08 02:56:25

问题


My target is to auto-name the output msi file with version number in WIX 3.6 project. I find this link: Automated installer version numbers for WiX, revisited but we have a slightly different scenario: we don't want to control our product version number by referencing to any assembly's version number. Instead, we just simply want to assign it in wix files. Specifically, I have a wxi file which defines a property like this:

<?define VersionNumber = "1.1.2000" ?>  

As a result, I can use this VersionNumber variable anywhere inside our Product.wxs file. But since the easiest way to rename the output msi file seems to be adding a postbuild task in MSBuild, I must pass this VersionNumber out to the MSBuild project file. This is what stops me.

I tried the other way around, i.e., to define the VersionNumber constant in the MSBuild and use it inside WIX. It works fine except I must keep this constant the same for different Build/Platform combinations. We are building our software in VS IDE which means if we modify the version number in IDE's window, it would only apply to the specific Build/Platform combination and the other combinations will remain unchanged(I know if I am building from command line I can simply pass a version number to overwrite the existing one). And that is what I don't want to see. I like the idea to only define the version number in one place to avoid any possible mistake.

Any help will be appreciated!


回答1:


Define the preprocessor variable after choosing "All Configurations" and "All Platforms" in the Build tab of the setup project properties.

You can achieve this by adding an element in your .wixproj to a project where you just keep the version number. You'd modify the .wixproj, but only once. And you can probably add this properties file to the .wixproj itself with a reasonable action (None?) so you can modify it from within the IDE.

Something like:

Version.properties

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
  <PropertyGroup>
    <WhateverTheVersionPropertyNameIs>x.x.x.x</WhateverTheVersionPropertyNameIs>
  </PropertyGroup>
</Project>

In your .wixproj file you'd add at the end

<Import Project="Version.properties"/>



来源:https://stackoverflow.com/questions/13233143/anyway-to-create-a-custom-msbuild-property-in-wix-wxs-file

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