############################################################ #incrementSetupProject.ps1 ################### # #DESCRIPTION: ################### #script to increment fields in the VS2005 Setup project, so that we can later install over an existing install (and automatically remove the previous version) # #DEPENDENCIES: ################### #-Powershell 2.0 (possibly also Windows XP SP3) ############################################################ #Change history ################### #$Log: incrementSetupProject.ps1,v $ #Revision 1.3 2011/01/21 17:02:47 seanr #PRN: 38502 - LuntBuild - LogViewer # - fixed issue, where Setup would fail, if LogViewer was already installed. # - now taking the buildnumber from LuntBuild (so that it is always incrementing) # #Revision 1.2 2011/01/21 16:55:31 seanr #PRN: 38502 - LuntBuild - LogViewer # - fixed issue, where Setup would fail, if LogViewer was already installed. # #Revision 1.1 2011/01/21 16:43:55 seanr #PRN: 38502 - LuntBuild - LogViewer # - fixed issue, where Setup would fail, if LogViewer was already installed. # ############################################################ #Process Summary ################### #We need to perform the following changes on the Setup project: #1. increment the final number, in the Setup version (e.g. 1.0.0 -> 1.0.1) #2. replace the ProductCode with a new GUID ############################################################ #Command line args ################### Param([string]$pathToLogViewer = "c:\DEVROOT\LogViewer-mainline-Release\LogViewer\", [string]$buildNumber) # the unique build number for this build: # This build number must be higher than the previous build, or else # we might not be able to install LogViewer over an existing install ! $isDebug = $false #change this to be $true if you want to see more in the log ############################################################ #Read in the Setup project file: ################### $pathToProject = $pathToLogViewer + "\src\LogViewerSetup\LogViewerSetup.vdproj" $projContents = gc $pathToProject ############################################################ #1. increment the final number, in the Setup version (e.g. 1.0.0 -> 1.0.1) ################### #the setup version looks like this in the project file: #"ProductVersion" = "8:1.0.2" $oldProductVersionLine = $projContents | ? { $_ -match '"ProductVersion" = "8:[0-9]\.[0-9]\.[0-9]{1,3}"' } write-host("oldProductVersionLine = " + $oldProductVersionLine) #substitute in our new ProductVersion (setup project version): $regexVerLastNum = ([regex]'[\.][0-9]+"') $verLastNumMatch = $regexVerLastNum.Matches($oldProductVersionLine.toString())[0] #result is like this: .21" $verLastNum = $verLastNumMatch.toString().Substring(1, $verLastNumMatch.Length-2) #trim off first + last chars $setupVer = $oldProductVersionLine.toString() if($isDebug) { write-host("setupVer: " + $setupVer + " - last number: " + $verLastNum) } $iVerNextNum = ([int]$buildNumber) $nextSetupVer = $setupVer.toString().substring(0, $setupVer.toString().Length - $verLastNumMatch.ToString().Length) if($isDebug) { write-host("nextSetupVer first = " + $nextSetupVer) } $nextSetupVer = $nextSetupVer + "." + $iVerNextNum.toString() + '"' write-host("nextSetupVer: " + $nextSetupVer) $projContents = ( $projContents | Foreach-Object {$_ -replace $oldProductVersionLine, $nextSetupVer} ) ############################################################ #2. replace the ProductCode with a new GUID ################### #the ProductCode looks like this in the project file: #"ProductCode" = "8:{CC96E143-57F2-4614-A0C3-C406CF95E86C}" $prodCodePrefix = '"ProductCode" = "8:{' $oldProductCodeLine = $projContents | ? { $_ -match $prodCodePrefix } write-host("oldProductVersionLine = " + $oldProductCodeLine) $oldProdCodePrefix = $oldProductCodeLine.substring(0, $oldProductCodeLine.Length - (36 + 3)) #create a new GUID, in the 'Windows Registry' format: $newGuid = [guid]::NewGuid() #lowercase $newGuidProdCodeLine = $oldProdCodePrefix + "{" + $newGuid.ToString().ToUpper() + '}"' write-host("next ProductCode line: " + $newGuidProdCodeLine) #substitute in our new ProductCode: $projContents = ( $projContents | Foreach-Object {$_ -replace $oldProductCodeLine, $newGuidProdCodeLine} ) ############################################################ #save our changes: write-host("saving changes to " + $pathToProject) $projContents | out-file -encoding 'UTF8' $pathToProject exit(0)