Is there a way to include the version number as part of the output.msi filename in a VS2008 Setup Project?
I'd like for example an output file called: "myinstaller-1.0.13.msi" where the version part is automatically set based on the version number I have put in the deployment project properties.
Same concept as Jim Grimmett's answer, but with less dependencies:
Some points of note:
MySetupProjectName.vdproj
should be changed to the name of your project file. Forgetting to change this results in a build error:'PostBuildEvent' failed with error code '1'
and theOutput
window shows which fileFINDSTR
could not open.Step by step description:
FINDSTR /B /R /C:" *\"ProductVersion\"" $(ProjectDir)MySetupProjectName.vdproj
"ProductVersion" = "8:x.y.z.etc"
line from the project file.FOR /F "tokens=2 delims== " %%V IN (...) DO ... %%~nxV ...
x.y.z.etc
part from the above result.$(BuiltOuputPath)
FOR %%I IN (...) DO ... %%~nI-%%~nxV%%~xI
foo.msi
tofoo-x.y.z.etc.msi
.REN "$(BuiltOuputPath)" ...
FOR ... DO FOR .. DO REN ...
Not sure whether you still require this or not but wanted answer this as we did similar kind of operation in the postbuild event. As far as the research I did this is not possible to set the file name as you want internally through setup process.
You can do this in other way by naming the output file through an external application in post build event.
Here is what you can do:
In the post build event ->
Create an application which will rename the msi file with the version number from the deployment project. Following is the code used for the application. This should fulfill your requirement I guess.
Getting msi properties code is used from alteridem article
I didn't want to use the .exe method above and had a little time spare so I started diggind around. I'm using VS 2008 on Windows 7 64 bit. When I have a Setup project, lets call it MySetup all the details of the project can be found in the file $(ProjectDir)MySetup.vdproj.
The product version will be found on a single line in that file in the form
Now, there IS a post-build event on a setup project. If you select a setup project and hit F4 you get a completely different set of properties to when you right-click and select properties. After hitting F4 you'll see that one of the is PostBuildEvent. Again assuming that the setup project is called MySetup the following will set the name of the .msi to include the date and the version
I'll take you through the above.
datevar is the current date in the form YYYYMMDD.
The findstr line goes through MySetup.vdproj, removes any line with PostBuildEvent in, then returns the single line left with productVersion in, and outputs it to a file. We then remove the quotes, spaces, turn dots into underscores.
The for line splits the remaining string on colon, and takes the second part, and outputs it to a file again.
We then set realvar to the value left in the file, and rename MySetup.msi to include the date and version.
So, given the ProductVersion above, if it was 27th March 2012 the file would be renamed to
Clearly using this method you could grab ANY of the variables in the vdproj file and include them in your output file name and we don't have to build any extra .exe programs to do it.
HTH
If you use a WIX project (as opposed to a VS Setup & Deployment project) then this article explains exactly how to achieve what you are after.
I did it with 2 lines in powershell.
Rename your existing .vdproj to be MySetup.vdproj.template and insert "${VERSION}" wherever you want to insert the version of your primary exe file.
VS will then detect the change in the vdproj file and ask you if you want to reload it.