winrar.msi_如何使WinRAR自动化以从setup.exe和MSI文件制作单个文件安装程序

winrar.msi

介绍 (Introduction)

如果要使用Visual Studio创建单个文件安装程序,则可以使用InstallShield LE,也可以将setup.exe和MSI文件重新打包为自解压文件。 本文介绍了如何使用WinRAR生成后者,从而生成外观专业的软件包。

First of all, you may be tempted to just provide the MSI file for the installation.  You should only do this if you expect your end users to ensure all .NET runtime requirements are present on the install target machine.  This might be adequate in some corporate environments, or for your friends, or for a group of developers, but otherwise Setup.exe bootstrapper should be included with your MSI file.

首先,您可能会想只提供用于安装的MSI文件。 仅当希望最终用户确保安装目标计算机上存在所有.NET运行时要求时,才应这样做。 在某些公司环境中,对于您的朋友或一组开发人员来说,这可能就足够了,但是在其他情况下,MSI文件应包含Setup.exe引导程序。

手动创建安装文件 (Creating the install file manually)

首先,我们将看一下以交互方式创建设置所涉及的步骤。

Select the Setup.exe and your MSI file and right click.  Select the “Add to Archive…” context menu choice.  Now you can edit the archive name, and check the “Create SFX” checkbox.

选择Setup.exe和您的MSI文件,然后单击鼠标右键。 选择“添加到存档...”上下文菜单选项。 现在,您可以编辑档案名称,并选中“创建SFX”复选框。

General Tab
Advanced tab
SFX General

On the General Tab, check “Create in the current folder” and add the option to run Setup.exe after extraction.  This will launch your installer when the user runs the self extractor.

在“常规”选项卡上,选中“在当前文件夹中创建”,然后添加选项以在解压缩后运行Setup.exe。 当用户运行自解压程序时,这将启动您的安装程序。

SFX Text and Icon tab
SFX Update tab
SFX Modes tab

Click “Ok” on the bottom of the SFX options dialog, and “Ok” again for the “Add” dialog.  If there are no errors, WinRAR should now create your self extract file.

单击SFX选项对话框底部的“确定”,然后再次单击“确定”以显示“添加”对话框。 如果没有错误,WinRAR现在应该创建您的自解压文件。

Well, this is all well and good, but with all these steps, it’s going to be impossible to keep doing this for every new release of your program.  You’ve created an automated build process for your installer—you don’t want to fiddle around with this GUI every time you rebuild.  Fortunately, WinRAR lets us have the exact same functionality through the command line.

好吧,这一切都很好,但是有了所有这些步骤,就不可能在程序的每个新发行版中都继续这样做。 您已经为安装程序创建了一个自动构建过程-您不想每次重建时都在使用该GUI。 幸运的是,WinRAR通过命令行使我们具有完全相同的功能。

从命令行创建安装文件 (Creating the install file from the command line)

First let’s create two text files, script.txt and list.txt.  You can put these anywhere that is convenient.  I put them both in the output directory for my installer build process, so that folder contains:

首先,我们创建两个文本文件script.txtlist.txt 。 您可以将它们放在方便的任何地方。 我将它们都放在安装程序构建过程的输出目录中,因此该文件夹包含:

Setup.exe

安装程序

MSI file

MSI文件

List.txt

List.txt

Script.txt

Script.txt

The VB.NET code I show later will refer to these files.

我稍后显示的VB.NET代码将引用这些文件。

List.txt is a file containing the full filenames of the files to include in the self extractor.  Put one file line or use wildcards.

List.txt是一个文件,包含要包含在自提取程序中的文件的完整文件名。 放置一个文件行或使用通配符。

C:\temp\New folder\setup.exe
C:\temp\New folder\Setup.msi

Script.txt contains value pairs that configure some of the SFX options.

Script.txt包含配置某些SFX选项的值对。

Title=My Application
Silent=1
Overwrite=1
Setup=setup.exe

Note that the icon will be specified in the command line of the call to WinRAR.

请注意,该图标将在WinRAR调用的命令行中指定。

This call will be constructed like this:

该调用的构造如下:

"<path to winrar>WinRAR.exe" a "<sfxfilepath>" @"<listfilepath>" –ep –sfx –z"<scriptpath>" -iicon"<pathtoicon>"

In VB.NET I use code similar to this to automate this step:

在VB.NET中,我使用类似于以下代码的代码来自动执行此步骤:

Private Sub BuildSFX(ByVal OutputPath As String, ByVal OutputFilename As String)
    Dim ExePath As String = "C:\Program Files\WinRAR\WinRAR.exe"
    Dim PathString As String = IO.Path.Combine(OutputPath, OutputFilename)
    Dim ScriptString As String = IO.Path.Combine(OutputPath, "script.txt")
    Dim ListString As String = IO.Path.Combine(OutputPath, "list.txt")

    Dim Options As String = String.Format("a  ""{0}"" @""{1}"" -ep -sfx -z""{2}""", PathString, ListString, ScriptString)
    Options &= " -iicon""C:\Temp\Icons\AppIcon.ico"""

    Process.Start(ExePath, Options)
End Sub

结论 (Conclusion)

WinRAR使您能够采用现有的安装和部署项目来创建setup.exe和MSI文件,并基于自解压的可执行文件发布单个文件安装程序。 可以从命令行自动创建此类SFX项目。 当然,在GUI和命令行中都可以使用其他选项。 请查看WinRAR帮助以获取有关命令和开关的信息。

I hope you find this useful.  Please take the time to browse my other articles, and please remember to vote if you find this helpful.

希望这个对你有帮助。 请花时间浏览我的其他文章,如果对您有帮助,请记得投票。

翻译自: https://www.experts-exchange.com/articles/10056/How-to-automate-WinRAR-to-make-a-single-file-installer-from-setup-exe-and-MSI-file.html

winrar.msi

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值