Monday 9 March 2009

Programmatically change the 'ProductName', 'ProductCode', 'UpgradeCode' and 'ShortCut' depending on build Configuration.

Use the following to update the 'ProductName', 'ProductCode', 'UpgradeCode' and 'ShortCut' in a MSI setup after it has been build in vs2005:

  1. Select the "Setup Project" in vs2005 and press F4.
  2. Change the "PostBuildEvent" to
    wscript "$(ProjectDir)UpdateMSI.vbs" "$(BuiltOuputPath)" "$(ProjectDir)" $(Configuration).
  3. Place the UpdateMSI.vbs file in "$(ProjectDir)". This file can be found here.

6 comments:

  1. can you paste the code from vbs into this page?
    thanks.

    ReplyDelete
  2. BuiltOuputPath = Wscript.Arguments(0)
    ProjectDir = Wscript.Arguments(1)
    Configuration = Wscript.Arguments(2)

    ProductName = "MyApplication - " & Configuration
    ShortcutName = "MYAPP~2|" & ProductName 'Check this with orca.exe

    select case Configuration
    case "Debug"
    UpgradeCode = "{11A3CB76-5DAC-4B9F-A993-401BE1D95A9E}"
    ProductCode = "{E1BFC46C-6226-459C-BC4F-8DE17888ED62}"
    case "Test"
    UpgradeCode = "{B15A5EAA-FA9C-4BB7-AD68-29DAE5C95846}"
    ProductCode = "{F183C852-5DBC-498C-89F1-2D6CDFF515B6}"
    case "Production"
    UpgradeCode = "{E14EC8A9-FA0B-47B8-84EB-4EC7ED278E7E}"
    ProductCode = "{016C6EF8-A23F-4822-96B2-E0A1D74641EE}"
    case Else

    end select

    'guid = CreateObject("Scriptlet.TypeLib").Guid
    'UpgradeCode = left(guid, len(guid) - 2)

    Const msiOpenDatabaseModeTransact = 1
    Dim propertyKey, propertyValue
    Dim installer, database, view, record
    Set installer = CreateObject("WindowsInstaller.Installer")
    Set db = Installer.OpenDatabase(BuiltOuputPath, msiOpenDatabaseModeTransact)
    Set view = db.OpenView("UPDATE Property SET Value = '" & ProductName & "' WHERE Property = '" & "ProductName" & "'")
    view.Execute
    Set view = db.OpenView("UPDATE Property SET Value = '" & ProductCode & "' WHERE Property = '" & "ProductCode" & "'")
    view.Execute
    Set view = db.OpenView("UPDATE Property SET Value = '" & UpgradeCode & "' WHERE Property = '" & "UpgradeCode" & "'")
    view.Execute
    Set view = db.OpenView("UPDATE Shortcut SET Name = '" & ShortcutName & "' WHERE Description = 'MyApplication Application'")
    view.Execute
    'Set view = db.OpenView("UPDATE Upgrade SET UpgradeCode = '" & UpgradeCode & "'")
    'view.Execute
    db.Commit
    Set installer = Nothing
    Set db = Nothing
    Set view = Nothing

    ReplyDelete
  3. How the MSI will be called/triggered.?
    physically where we have to place the vbs file ?
    Does user need to trigger msi / vbs to get install?

    Please help on this.

    ReplyDelete
  4. Can we pass those 3 arguments when we trigger MSI?

    ReplyDelete
  5. Call the VBS in the post-build event from the Web.Setup project:

    "PostBuildEvent" = "8:wscript \"$(ProjectDir)UpdateMSI.vbs\" \"$(BuiltOuputPath)\" \"$(ProjectDir)\" $(Configuration)"

    ReplyDelete