Reputation: 7772
Is this possible to generate new folder based on project Assembly version
or <?define ProductVersion="1.0.0.0" ?>
version in WIX config file when i build installer project(like ClickOnce publish button).
I want something like this:
MyProjectPublishes/
----MyProject1.0.0.0/
MyProjectSetup.msi
----MyProject2.0.0.0/
MyProjectSetup.msi
----MyProject3.0.0.0/
MyProjectSetup.msi
Upvotes: 1
Views: 521
Reputation: 3321
Yes, but keep in mind that your MSIs shouldn't be major upgrades or they will remove previous versions (unless that's what you want; presumably you want side-by-side folders so they can all be installed simultaneously).
First, understand that you shouldn't hardcode component GUIDs either. While it is supported to have the same component GUIDs go to different folders, it creates a number of problems with updates and uninstall best avoided. It's also a pain to maintain, so just use auto-GUID'ing for components.
Create directory authoring like so (assumes you pass in a ProductVersion variable):
<?define ProductName="MyProduct"?>
<?ifndef ProductVersion?>
<?define ProductVersion=1.0.0?>
<?endif?>
<Product Name="$(var.ProductName)" Version="$(var.ProductVersion)" ...>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder" Name="Program Files">
<Directory Id="INSTALLDIR" Name="$(var.ProductName)">
<Directory Id="VersionDir" Name="$(var.ProductVersion)"/>
</Directory>
</Directory>
</Directory>
</Product>
This is just a sample snippet of the directory table. I defined INSTALLDIR as the root product path so that you control all versions going into per-version directories so the user can't accidentally stomp over previous versions with different component GUIDs (different component GUIDs to the same location causes files to be removed on uninstall since they aren't ref-counted).
To install then, you can do:
<Component Directory="VersionDir">
<File Source="foo.dll"/>
</Component>
Notice that I didn't specify the GUID, nor any other ID for that matter. They'll be generated, and the GUID will be stable (meaning, using the same version, all subsequent rebuilds will have the same GUID until you change the version - which is exactly how it should work).
To see an example of this in use (as well as how to get the version from a file in a referenced C# project), see https://github.com/heaths/psmsi/tree/develop/src/Setup.
Upvotes: 1