Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
797 views
in Technique[技术] by (71.8m points)

visual studio - How to include version number in VS Setup Project output filename

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

ProductVersion="8:1.0.0"

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

set datevar=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%
findstr /v PostBuildEvent $(ProjectDir)MySetup.vdproj | findstr ProductVersion >$(ProjectDir)version.txt
set /p var=<$(ProjectDir)version.txt
set var=%var:"=%
set var=%var: =%
set var=%var:.=_%
for /f "tokens=1,2 delims=:" %%i in ("%var%") do @echo %%j >$(ProjectDir)version.txt
set /p realvar=<$(ProjectDir)version.txt
rename "$(ProjectDir)$(Configuration)MySetup.msi" "MySetup-%datevar%-%realvar%.msi"

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

MySetup-20120327-1_0_0.msi

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...