在Visual Studio安装项目中,如何生成卸载脚本? [英] In a Visual Studio setup project, How do I generate an uninstall script?

查看:99
本文介绍了在Visual Studio安装项目中,如何生成卸载脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Visual Studio安装项目. 安装后,它将在应用程序文件夹中创建一个卸载批处理文件.如果用户要卸载产品,则可以转到添加/删除程序",或者只需双击uninstall.cmd.内容是:

I have a Visual Studio setup project. Upon installation, it creates an uninstall batch file in the application folder. IF the user wants to uninstall the product, he can go to "Add/Remove Programs", or he can just double-click the uninstall.cmd. The contents are:

%windir%\system32\msiexec /x {CC3EB7BF-DD82-48B9-8EC5-1B0B62B6D285}

GUID是Visual Studio中安装项目中的ProductCode.

The GUID there is the ProductCode from the Setup Project in Visual Studio.

但是,为了使升级正常进行,每次生成新的MSI时,我都必须增加版本号.而且,如果我增加版本号,那么我还必须为ProductCode生成一个新的Guid.这意味着需要更改静态uninstall.cmd文件.

But, in order for upgrades to work properly, I have to increment the Version number, every time I produce a new MSI. And, if I increment the Version number, then I also have to generate a new Guid for the ProductCode. Which means the static uninstall.cmd file needs to change.

如何在构建时动态生成包含其ProductCode的批处理文件?

How can I dynamically generate a batch file that contains the ProductCode for the, at build time?

推荐答案

这是我编写的用于创建uninstall.cmd的脚本.它在安装过程中作为自定义操作运行.

This is the script I wrote that creates an uninstall.cmd. It runs as a custom action during installation.

var fso, ts;
var ForWriting= 2;
fso = new ActiveXObject("Scripting.FileSystemObject");

var parameters = Session.Property("CustomActionData").split("|"); 
var targetDir = parameters[0];
var productCode = parameters[1];

ts = fso.OpenTextFile(targetDir + "uninstall.cmd", ForWriting, true);

ts.WriteLine("@echo off");
ts.WriteLine("goto START");
ts.WriteLine("=======================================================");
ts.WriteBlankLines(1);
ts.WriteLine(" Uninstall.cmd");
ts.WriteBlankLines(1);
ts.WriteLine("=======================================================");
ts.WriteBlankLines(1);
ts.WriteLine(":START");
ts.WriteLine("@REM The uuid is the 'ProductCode' in the Visual Studio setup project");
ts.WriteLine("%windir%\\system32\\msiexec /x " + productCode);
ts.WriteBlankLines(1);
ts.Close();

结果是一个cmd文件,其中始终包含当前的ProductCode.

The result is a cmd file that always has the current ProductCode in it.

其缺点是?创建uninstall.cmd 的脚本仍保留在安装目录中.这不是一个大问题,但我不喜欢install目录中的垃圾.我尚未尝试使"createInstaller.js"自删除.那可能行得通.

The downside of this is that ?the script that creates the uninstall.cmd remains in the installation directory. Not a huge problem but I don't like the rubbish in the install directory. I haven't yet tried to make the "createInstaller.js" self-deleting. That might work.

编辑:是的,使createInstaller.js自删除可以正常工作.

EDIT: yes, making the createInstaller.js self-deleting works fine.

我将接受自己的答案!

I'm going to accept my own answer!

这篇关于在Visual Studio安装项目中,如何生成卸载脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆