2

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!

tete
  • 4,859
  • 11
  • 50
  • 81
  • Why do you need to keep it for each build/platform combination? Just add it in a with no conditions. – fsimonazzi Nov 05 '12 at 13:34
  • @fsimonazzi I just updated my original post. I could be wrong but the problem is since we are building our SW in Visual Studio IDE, not from command line, we surely don't want to modify the .wixproj file(to modify the version number) directly by unloading/loading. But if we modify it from IDE, VS assumes we want to change it for the certain Build/Platform, and when we switch to another one, this value remains as the original one. – tete Nov 05 '12 at 13:40

1 Answers1

2

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"/>

fsimonazzi
  • 2,975
  • 15
  • 13
  • Thanks for your reply. My knowledge regarding MSBuild is very limited, but I think I get what you mean. I should add a new project (if so, what would be the type of this project?) which only includes the version number. And then in this new project's properties IDE window, I can modify this number. Am I right? However, I tried to add a normal .vbproj project, and overwrite with your code, but in the IDE I can't see any place showing this property – tete Nov 05 '12 at 14:36
  • No, just create a plain text file and add that content. Update the .wixproj file once to import it, and you should be done. – fsimonazzi Nov 05 '12 at 14:39
  • It won't be a project in Visual Studio, just a plain file. If the wix project allows it, it could be a file in that project. If not, a file in the solution. Make sure you create in the wix project folder though, or change the Import element to point to the appropriate location. – fsimonazzi Nov 05 '12 at 14:41
  • Yes, I did create a plain text file, copy your above content, and rename this file to Version.properties(the extension name probably doesn't matter), and then in my wixproj file just import it. Since my project actually loaded fine, I assume at least the location is correct and MSBuild somehow understands this file. However, I still can't find the new property displayed in IDE. In the properties window of my WIX project, there are "Installer", "Build", "Build Events", "Paths" and "Tool Settings" tabs, but none of them has it. If it matters, I am using VS2012. Do I have to do something else? – tete Nov 05 '12 at 14:53
  • Went back to the IDE (I don't usually rely on wixprojs). You already have support built in to edit in one place: go to the Build tab, and select "All Configurations" and "All platforms" and set the values there. It will still be a copy, but the UI will take care of that. If you want to stick to the original solution, you'll have to edit the file rather than going through the project properties. – fsimonazzi Nov 05 '12 at 15:05
  • OK, now I fully understand what you suggest: you mentioned two options, 1) To import a plain text file as project and modify version number there directly. 2) To add a preprocessor variable in the IDE under "All Configuration/Platform", VS will actually make copies to all PropertyGroup but at least we only need to add at one place. Option 2) is still a little bit problematic because there is a chance our build engineer modifies individual Config/Platform and makes them out of sync, especially due to the fact the default view is Active Config/Platform. I'll try 1) at first. Thank you so much! – tete Nov 05 '12 at 15:39