Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting the file version of a native exe in MSBuild
    primarykey
    data
    text
    <p>I have a number of Visual C++ projects in a Visual Studio 2010 solution. Also in this solution is a WiX project that builds the installer for the executable that is the product of one of the C++ projects.</p> <p>The executable has a resource file in its project which writes the version of the program to the executable.</p> <p>Now I'd like to version the WiX-built installer with the same number as the one written to the executable by the resource file. I've searched the WiX related posts on StackOverflow and found this post: </p> <p><a href="https://stackoverflow.com/questions/8400868/referencing-a-wixvariable-defined-in-a-wix-library-project-from-a-wix-setup-proj">Referencing a WixVariable defined in a WiX Library Project from a WiX Setup Project</a></p> <p>The accepted answer to which, seems to indicate that a possible solution is to use MSBuild and the GetAssemblyIdentity task in the BeforeBuild Target to acquire the version number from another file (in the case of the SO question a DLL, in my case the executable) and expose it to WiX before WiX builds the installer.</p> <p>I tried adding this to the MSBuild portion of my .wixproj file but when I try to build the installer I get an error returned saying:</p> <pre><code>error MSB3441: Cannot get assembly name for "&lt;ExePath&gt;". Could not load file or assembly '&lt;ExeName&gt;.exe' or one of its dependencies. The module was expected to contain an assembly manifest. </code></pre> <p>I can't seem to find any information on MSDN about this error as it relates to MSBuild. I've checked the built executable and it definitely has a version number on it (as well as the rest of the information from the .rc file) and the WiX project depends on the project that outputs the executable; so I assume its BeforeBuild task is running after the project it depends on has been built completely. </p> <p>Should I be using a different task instead of GetAssemblyIdentity to retrieve the version number from the .exe in MSBuild, are there other requirements to satisfy before GetAssemblyIdentity will work, or is it just not possible to get this type of information about .exe files in MSBuild?</p> <p><strong>EDIT :</strong> </p> <p>I accepted Rob's answer since I was misunderstanding the difference between ProductVersion and FileVersion, and the WiX technique that he suggested was working as intended and is a step towards the solution I needed. </p> <p>FileVersion is an attribute of executables only. Msi files are essentially databases and ProductVersion is an entry in that database; they have no FileVersion attribute to set. The method he suggests correctly sets ProductVersion in the .msi database.</p> <p>The title of this question is now not really related to what the problem I actually had was, since I was asking for a solution I believed I needed at the time. I've now solved the root problem which was simply getting access to the ProductVersion of the installer. I found a cscript script posted online here: <a href="http://kentie.net/article/wixnameversion/index.htm" rel="nofollow noreferrer">http://kentie.net/article/wixnameversion/index.htm</a> that shows how to access the ProductVersion of the .msi. Using that has allowed me to extract the ProductVersion and use it in other tools.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload