How to include version number in VS Setup Project output filename

前端 未结 6 1263
既然无缘
既然无缘 2020-12-08 04:58

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: \"myinstall

6条回答
  •  渐次进展
    2020-12-08 05:52

    Same concept as Jim Grimmett's answer, but with less dependencies:

    FOR /F "tokens=2 delims== " %%V IN ('FINDSTR /B /R /C:" *\"ProductVersion\"" "$(ProjectDir)MySetupProjectName.vdproj"') DO FOR %%I IN ("$(BuiltOuputPath)") DO REN "$(BuiltOuputPath)" "%%~nI-%%~nxV%%~xI"
    

    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 the Output window shows which file FINDSTR could not open.

    Step by step description:

    FINDSTR /B /R /C:" *\"ProductVersion\"" $(ProjectDir)MySetupProjectName.vdproj

    • This finds the "ProductVersion" = "8:x.y.z.etc" line from the project file.

    FOR /F "tokens=2 delims== " %%V IN (...) DO ... %%~nxV ...

    • This is used to parse out the x.y.z.etc part from the above result.

    $(BuiltOuputPath)

    • This is the original output path, as per what it says in Post-build Event Command Line's "Macros".

    FOR %%I IN (...) DO ... %%~nI-%%~nxV%%~xI

    • This is used to convert the string foo.msi to foo-x.y.z.etc.msi.

    REN "$(BuiltOuputPath)" ...

    • This just renames the output path to the new name.

    FOR ... DO FOR .. DO REN ...

    • It's written on one line like this so that an error along way cleanly breaks the build.

提交回复
热议问题