I have several deployment projects. In order to deploy an application, I need to do several tasks, one of them is to change each deployment project's product version and product code.
I can't find a way to programmatically change them.
Since it's a Deployment project (which finally produces an executable installer), I'm not able to work with MSBuild, instead I'm using the Devenv from the command prompt.
I was searching for the exact same thing today. I found this using google:
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();
}
}