Leon Barkan
Leon Barkan

Reputation: 2703

How to change setup project version (in TFS 2015 [vNext build])

for building my project setup file\msi in TFS 2015 i use

devenv Command Line task:

solutionPath /build BuildConfiguration /project projectPath

My question is how can i change msi version (if it's possible) from that line like ... $(BuildVersion)

Checked MSDN devenv command line (nothing.)

thanks

Upvotes: 1

Views: 713

Answers (2)

Simon Foley
Simon Foley

Reputation: 189

Same idea as Cece's solution but with a .vbs script that takes the .vdproj filename as first argument and the version as 2nd argument (**.**.** format) :

'Function that generates a new GUID
Function CreateGUID
  Dim TypeLib
  Set TypeLib = CreateObject("Scriptlet.TypeLib")
  CreateGUID = Mid(TypeLib.Guid, 2, 36)
End Function

Const ForReading = 1
Const ForWriting = 2

'Read vdproj filename and new version from arguments and generate new Guid
installerFileName = Wscript.Arguments(0)
newProductVersion = Wscript.Arguments(1)
newProductCode = CreateGUID()
newPackageCode = CreateGUID()

'Prepare Regexs
Set productVersionRegex = New RegExp
With productVersionRegex
 .Pattern    = Chr(34) & "ProductVersion" & Chr(34) & " = " & Chr(34) & "8:(.*)" & Chr(34)
 .IgnoreCase = False
End With

Set productCodeRegex = New RegExp
With productCodeRegex
 .Pattern    = Chr(34) & "ProductCode" & Chr(34) & " = " & Chr(34) & "8:{(.*)}" & Chr(34)
 .IgnoreCase = False
End With

Set packageCodeRegex = New RegExp
With packageCodeRegex
 .Pattern    = Chr(34) & "PackageCode" & Chr(34) & " = " & Chr(34) & "8:{(.*)}" & Chr(34)
 .IgnoreCase = False
End With

'Read Text from installer file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(installerFileName, ForReading)
installerText = objFile.ReadAll
objFile.Close

'Replace ProductVersion
newProductVersionString = Chr(34) & "ProductVersion" & Chr(34) & " = " & Chr(34) & "8:" & newProductVersion & Chr(34)
installerNewText = productVersionRegex.Replace(installerText, newProductVersionString)

'Replace ProductCode Guid
newProductCodeString = Chr(34) & "ProductCode" & Chr(34) & " = " & Chr(34) & "8:{" & newProductCode & "}" & Chr(34)
installerNewText = productCodeRegex.Replace(installerNewText, newProductCodeString)

'Replace UpgradeCode  Guid
newPackageCodeString = Chr(34) & "PackageCode" & Chr(34) & " = " & Chr(34) & "8:{" & newPackageCode & "}" & Chr(34)
installerNewText = packageCodeRegex.Replace(installerNewText, newPackageCodeString)

'Write new Text in installer file
Set objFile = objFSO.OpenTextFile(installerFileName, ForWriting)
objFile.Write installerNewText
objFile.Close

The script can be called like this :

cscript script.vbs Installer.vdproj 1.2.5

Upvotes: 0

Cece Dong - MSFT
Cece Dong - MSFT

Reputation: 31075

Assumning you want to change the ProductVersion value in .vdproj file during build. You are correct that there is no command to change this directly.

You need to use powershell or programatically change the version. Here is a code snippet in this case you can refer to:

static void Main(string[] args) 
{
    string setupFileName = @"<Replace the path to vdproj file>"; 
    StreamReader reader = File.OpenText(setupFileName); 
    string file = string.Empty; 

    try 
    { 
        Regex expression = new Regex(@"(?:\""ProductCode\"" = 
        \""8.){([\d\w-]+)}"); 
        Regex expression1 = new Regex(@"(?:\""UpgradeCode\"" = 
        \""8.){([\d\w-]+)}"); 
        file = reader.ReadToEnd(); 

        file = expression.Replace(file, "\"ProductCode\" = \"8:{" + 
        Guid.NewGuid().ToString().ToUpper() + "}"); 
        file = expression1.Replace(file, "\"UpgradeCode\" = \"8:{" 
        + Guid.NewGuid().ToString().ToUpper() + "}"); 
    } 
    finally 
    { 
        // Close the file otherwise the compile may not work 
        reader.Close(); 
    } 

    TextWriter tw = new StreamWriter(setupFileName); 
    try 
    { 
        tw.Write(file); 
    } 
    finally 
    { 
        // close the stream 
        tw.Close(); 
    } 
 }

Or you can refer to the powershell script that replace AssemblyVersion from AssemblyInfo.cs in this case to change ProductVersion value in .vdproj file.

Upvotes: 1

Related Questions