Justin
Justin

Reputation: 627

Adding A Version To Post-Build Event In WiX

I'm new to WiX and having some trouble achieving what I think should be really simple. I'm using WiX v3.8 in Visual Studio 2013. Overall what I'm trying to accomplish is having one place where I can change the version of the installer and this will be propagated throughout the WiX project.

In the project properties of the WiX project => Build tab => "Define preprocessor variables" textbox I have: ProjectVersion=3.6.7.0

However, where i run into problems is in the Post-Build Events when this fails:

copy !(TargetPath) "C:\Development\Release Builds\MyProject\$(TargetName) $(var.ProjectVersion)$(TargetExt)"

I've been scouring the internet, but unable to find a solution to my problem. Maybe I just don't know what to ask?

My question is: How can I make this post-build event work? What am I doing wrong? All I want to do is be able to do is easily change the ProjectVersion variable or another such variable in the post-build event.

Upvotes: 1

Views: 4241

Answers (1)

jmelhus
jmelhus

Reputation: 1140

This isn't exactly what you are asking for, but maybe it can help you achieve what you want?

I do it slightly different than your approach. I read the version from my 'main' assembly bundled with the wix installer, renames the msi filename to contain the version string, and sign it afterwards in a post-build event.

Resources:

https://stackoverflow.com/a/19371257/767926

https://stackoverflow.com/a/12323770/767926

To rename the msi to contain the version in the filename (wixproj):

<Target Name="BeforeBuild">
    <GetAssemblyIdentity AssemblyFiles="$(SolutionDir)'HARDCODED PATH'\bin\$(Configuration)\'HARDCODED NAME OF ASSEMBLY'">
        <Output TaskParameter="Assemblies" ItemName="AssemblyVersions" />
    </GetAssemblyIdentity>
    <CreateProperty Value="$(OutputName).%(AssemblyVersions.Version)">
        <Output TaskParameter="Value" PropertyName="TargetName" />
    </CreateProperty>
    <CreateProperty Value="$(TargetName)$(TargetExt)">
        <Output TaskParameter="Value" PropertyName="TargetFileName" />
    </CreateProperty>
    <CreateProperty Value="$(TargetDir)$(TargetFileName)">
        <Output TaskParameter="Value" PropertyName="TargetPath" />
    </CreateProperty>
</Target>

To sign the msi after the renaming (wixproj):

<PropertyGroup>
    <PostBuildEvent>"C:\Program Files\Microsoft SDKs\Windows\v7.0A\Bin\signtool.exe" sign /sha1 'CERTIFICATEHASH' /v /t http://timestamp.verisign.com/scripts/timstamp.dll /d "DESCRIPTION" "$(ProjectDir)\bin\$(ConfigurationName)\'HARCODED PARTIAL MSI NAME'@(AssemblyVersions->'%(Version)').msi"</PostBuildEvent>
</PropertyGroup>

It's important to manually add/edit this post-build event in the wixproj file(use the editor), if you use the GUI it will mess up:

@(AssemblyVersions->'%(Version)')

Also, if you would like to sign your MSI's, make sure you add a description for the MSI, otherwise the UAC prompt will show a temporary filename. Resource: http://kentie.net/article/wixtipstricks/

Upvotes: 5

Related Questions