我有一个没有任何源代码的安装程序。我需要“包装”此安装程序或对其进行编辑以添加更多文件。最好的方法是什么?正如标题所提到的,安装程序是用 ghost 安装程序编写的。
1 回答
由于它不是 MSI,因此您不能使用Orca 来编辑安装程序本身。而且我之前也为我的 MSI 安装程序编写了自定义安装操作。
由于您对 Ghost 安装程序没有太多控制(如果有的话),我可能会编写一个自定义可执行文件来补充安装程序,它可以在安装程序之前或之后运行。这将创建一些额外的文件以分发给您的客户,但您可以将整个文件分发为 zip 存档。
首先,如果您想像 Visual Studio 一样创建一个非托管引导程序以确保安装先决条件,您可以通过 MSBuild 使用如下脚本来完成:
<Project ToolsVersion="3.5" DefaultTargets="BuildBootstrapper" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<BootstrapperFile Include="Microsoft.Net.Framework.2.0">
<ProductName>Microsoft .NET Framework 2.0</ProductName>
</BootstrapperFile>
</ItemGroup>
<Target Name="BuildBootstrapper">
<GenerateBootstrapper
ApplicationFile="CustomInstallerExecutable.exe"
ApplicationName="Pretty Title of Application Goes Here"
BootstrapperItems="@(BootstrapperFile)"
ComponentsLocation="Relative" />
</Target>
</Project>
这将生成一个“setup.exe”,它是安装程序的任何引导程序的实际文件名。事实上,如果您想确保用户不会意外跳过引导程序并直接进入安装程序,您可以将 Ghost 安装程序隐藏在“bin”文件夹或远离 zip 存档根目录的地方。这样,他们唯一直观的选择就是“setup.exe”。如果您为了客户的缘故需要非常清楚,也包括一个“README.txt”。
此引导程序还确保客户端具有 .NET 2.0 框架作为先决条件,以便您的“CustomInstallerExecutable.exe”可以用 .NET 而不是非托管语言编写。事实上,这个 MSBuild 脚本会在新创建的引导程序旁边弹出 .NET 2.0 Framework 安装程序(因为“ComponentsLocation”属性的“Relative”值)。如果您担心将 Ghost 安装程序下载的原始下载大小膨胀给客户,您可以使用其他属性值来帮助用户通过 Web 获取 .NET Framework。
现在,您的“CustomInstallerExecutable.exe”(用漂亮的托管 C# 编写)可以在运行 Ghost 安装程序之前(或之后)将额外文件放到机器上。我之前编写了一些代码来从 .NET 可执行文件运行 MSI:
string msiString = "blahBlah.msi";
// Kick off Update installer
ProcessStartInfo startInfo = new ProcessStartInfo(
"cmd.exe",
"/c start /wait msiexec.exe /i " + msiString);
startInfo.WorkingDirectory = "bin";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
Process process = new Process
{
StartInfo = startInfo,
EnableRaisingEvents = true
};
process.Exited += new EventHandler(process_Exited);
process.Start();
我认为你可以做一些非常相似的事情来调用你的 Ghost 安装程序而不是 MSI。如果您在 Ghost 安装程序之前运行此 .NET 可执行文件,则只需调用 Ghost 安装程序进程,然后退出“CustomInstallerExecutable.exe”进程,而无需等待 process.Exited 事件触发。此事件等待将更多用于运行“安装后”逻辑。
祝你好运,希望这会有所帮助。