I am using the windows installer to install/upgrade an installation.
Using Visual Studio I can manually change the version number and then select yes when asked to change the ProductCode. This creates an installer that is capable of overwriting the existing installation provided that the following properties are set on the installer project
RemovePreviousVersions True
DetectNewerInstalledVersion True
Now in my build server I can change the version number to the appropriate new version in the .vdproj project.
Can somebody advise on how to generate a new ProductCode for the project from the command line or a batch script?
The solution is to use uuidgen
uuidgen -c
will generate the appropriate ProductCode.
The following batch script will update the product code and allow for an overwrite install when applied through a build server prior to performing a release build.
REM
REM Batch file to set the release number and version number for a production release
REM
REM
if not defined RELEASE_VERSION exit /b 1
if not defined BUILD_NUMBER exit /b 1
if not defined SVN_REVISION exit /b 1
set SDKBIN=%PROGRAMFILES%\Microsoft SDKs\Windows\v7.0A\Bin
if defined PROGRAMFILES(X86) Set SDKBIN=%PROGRAMFILES(X86)%\Microsoft SDKs\Windows\v7.0A\Bin
REM Change the version details in the WindowsInstaller project
fart WindowsInstaller\WindowsInstaller.vdproj "\"ProductVersion\" = \"8:1.0.0\"" "\"ProductVersion\" = \"8:%RELEASE_VERSION%.%BUILD_NUMBER%\""
if %ERRORLEVEL%==0 exit /b 1
for /f %%i in ('"%SDKBIN%\uuidgen" -c') do set PRODUCTCODE=%%i
if not defined PRODUCTCODE exit /b 2
fart WindowsInstaller\WindowsInstaller.vdproj "\"ProductCode\" = \"8:{2DD6303F-BF0C-4CD5-9AAC-171C577FFEAD}\"" "\"ProductCode\" = \"8:{%PRODUCTCODE%}\""
if %ERRORLEVEL%==0 exit /b 1
exit /b 0
I use fart to perform the regex replacement in the source file.
As you can see Visual Studio Setup Projects are already deprecated:
http://blogs.msdn.com/b/buckh/archive/2011/03/17/visual-studio-setup-projects-vdproj-will-not-ship-with-future-versions-of-vs.aspx
It would make more sense to migrate to WIX as soon as you can. It does have a learning curve, but it is not as bad as some people make it out to be. If you start the right way you'll be there in no time. The key is to go sample based and implement the basics first. There is a degree of "automagic" in Wix which will help you to do things right if you read the help file properly.
See my answer here for a few good pointers: https://stackoverflow.com/a/22550256/129130 - Particularly the codeproject link might be a good start.
Wix has new features to automatically change the product code and package code for every build.
Wix will automatically generate a new ProductCode for your installer if you set Product/@Id
to *
:
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="myproduct" ... >
...
</Product>
</Wix>
The PackageCode
is normally automatically generated. The documentation says that you should always generate a new package code for a product, so the attribute can be omitted. For a merge module you do have to specify the package code, but otherwise you shouldn't use it.
The UpgradeCode
specifies the family of related products. Major upgrades will only work between packages that were labelled with the same UpgradeCode
.
To support major upgrades, it's simplest to use the MajorUpgrade
element. It defaults to preventing downgrades - you specify the DowngradeErrorMessage
attribute to provide a message if the user tries to do this. All you need is the following:
<MajorUpgrade
DowngradeErrorMessage="A later version of [ProductName] is already installed. Setup will now exit.">