Get the newest uninstaller for the updated ProductCode in VS 2010
When we are using the VS 2010 and trying to release our application to the customer, we sometimes use the default deployment project to create a simple msi package as the solution. But if any update is released, it is very important to change the Version/ProductCode of our vdproj project, and we need to modify the uninstaller’s ProductCode. If more projects, we need modify more uninstallers. Is there any solution or workaround to avoid the bothering work? Of course, there is.
1. You should get the following code to create a project named “ProductCodeFixer”:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
class Program { //origub ProductCode: private static string OriCode = "0F67F96D-15F3-4BCC-BF13-9B634C2D7A48"; private static string targetExe = Path.Combine(System.Windows.Forms.Application.StartupPath, "Uninstall.exe"); static void Main(string[] args) { if (args.Length == 0 || !File.Exists(args[0]) || !args[0].Contains(".vdproj")) { Console.WriteLine("could not find .vdproj file"); return; } Console.WriteLine("ProductCodeFixer start"); string dir = System.Windows.Forms.Application.StartupPath; string productCode = ""; Console.WriteLine("Fixing File from: " + args[0]); using (StreamReader sr = new StreamReader(args[0])) { string entireFile = sr.ReadToEnd(); Regex regex = new Regex("(?<=\"ProductCode\" = \"8:{).*?(?=}\")"); Match match = regex.Match(entireFile); if (string.IsNullOrEmpty(match.Value)) { Console.WriteLine("Could not find product in: " + args[0]); return; } if (match.Value.Length != OriCode.Length) { Console.WriteLine("Matched string does not the ProductCode"); return; } productCode = match.Value; } if (!string.IsNullOrEmpty(productCode)) { using (FileStream fs = new FileStream(targetExe, FileMode.Open, FileAccess.ReadWrite)) { fs.Position = 1974; foreach(char ch in productCode) { fs.WriteByte((byte)ch); fs.WriteByte(0); } } Console.WriteLine("Fix complete"); } } } |
2. Add the ProductCodeFixer to uninstaller’s directory, and set an vdproj file path as a parameter, the ProductCodeFixer will automaticly change the uninstaller’s version.
Note: You can get the uninstaller from here.
3. Before creating the msi package, we should add PreBuildEvent to our project like the following: “$(ProjectDir)\xxxx\ProductCodeFixer.exe” “$(ProjectDir)\xxxx\our_proj.vdproj” . After running PreBuildEvent, you’ll get a new uninstaller for the new msi package.