El TecnoBaúl de Kiquenet

Kiquenet boring stories

Modificar programáticamente ProductCode de Setup Project

Posted by kiquenet en 17 agosto 2012

Existen varias alternativas:

Proyecto en VS .NET C#:

VS.NET Deployment Project Updater
http://vdprojectupdater.codeplex.com/

http://www.codeproject.com/Articles/5760/VS-NET-Deployment-Project-Version-Updater

En C# con expresiones regulares:

 

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();
}
}

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

  1. Select the “Setup Project” in vs2005 and press F4.
  2. Change the “PostBuildEvent” towscript “$(ProjectDir)UpdateMSI.vbs” “$(BuiltOuputPath)” “$(ProjectDir)” $(Configuration).
  3. Place the UpdateMSI.vbs file in “$(ProjectDir)”.
BuiltOuputPath = Wscript.Arguments(0)

ProjectDir = Wscript.Arguments(1)

Configuration = Wscript.Arguments(2)

ProductName = "MyApplication - " &amp; Configuration

ShortcutName = "MYAPP~2|" &amp; 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 = '" &amp; ProductName &amp; "' WHERE Property = '" &amp; "ProductName" &amp; "'")

view.Execute

Set view = db.OpenView("UPDATE Property SET Value = '" &amp; ProductCode &amp; "' WHERE Property = '" &amp; "ProductCode" &amp; "'")

view.Execute

Set view = db.OpenView("UPDATE Property SET Value = '" &amp; UpgradeCode &amp; "' WHERE Property = '" &amp; "UpgradeCode" &amp; "'")

view.Execute

Set view = db.OpenView("UPDATE Shortcut SET Name = '" &amp; ShortcutName &amp; "' WHERE Description = 'MyApplication Application'")

view.Execute

'Set view = db.OpenView("UPDATE Upgrade SET UpgradeCode = '" &amp; UpgradeCode &amp; "'")

'view.Execute

db.Commit

Set installer = Nothing

Set db = Nothing

Set view = Nothing

Con MSBuild:

How to auto-increment assembly version using a custom MSBuild task

http://weblogs.asp.net/bradleyb/archive/2005/12/02/432150.aspx

También hay herramientas de terceros como Stampver:

http://www.elphin.com/downloads/stampver/

Referencias:

http://stackoverflow.com/questions/306233/how-to-programatically-change-a-projects-product-version

Anuncios

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s

 
A %d blogueros les gusta esto: