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

查看:17
本文介绍了在 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%system32msiexec /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的脚本保留在安装目录中.不是什么大问题,但我不喜欢安装目录中的垃圾.我还没有尝试使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天全站免登陆