自从[Run]
部分处理后[Files]
部分,用您所显示的脚本自然不可能做到这一点(因此您的问题)。有几种方法,我推荐的一种方法是从以下位置执行 .NET 设置:AfterInstall设置条目本身的参数功能。所以你会删除当前的[Run]
部分并编写如下脚本:
[Files]
Source: "dependencies\dotNetFx40_Full_x86_x64.exe"; DestDir: {tmp}; Flags: deleteafterinstall; AfterInstall: InstallFramework; Check: FrameworkIsNotInstalled
Source: "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\MySql.Data\v4.0_6.5.4.0__c5687fc88969c44d\MySql.Data.dll"; DestDir: "{app}\lib"; StrongAssemblyName: "MySql.Data, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, ProcessorArchitecture=MSIL"; Flags: gacinstall sharedfile uninsnosharedfileprompt
[Code]
procedure InstallFramework;
var
ResultCode: Integer;
begin
if not Exec(ExpandConstant('{tmp}\dotNetFx40_Full_x86_x64.exe'), '/q /norestart', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
begin
{ you can interact with the user that the installation failed }
MsgBox('.NET installation failed with code: ' + IntToStr(ResultCode) + '.',
mbError, MB_OK);
end;
end;
这个过程很简单,如果Check
.NET 设置条目的功能[Files]
部分评估为 True (FrameworkIsNotInstalled),处理该条目,将安装二进制文件复制到 Inno Setup 的临时文件夹中,如果成功,则AfterInstall
功能InstallFramework
之后立即调用。在此函数内部,.NET 设置是通过调用手动执行的Exec功能。
最后,如果所有这些都成功,安装将继续处理下一个[Files]
节条目,这是要注册的程序集。现在,安装了 .NET 框架。正如你所看到的,[Files]
部分条目在这里至关重要。
您还在评论中询问了如何向用户显示一些进度,因为以我在此处发布的方式执行 .NET 设置会阻止[Files]
条目,这会导致显示停止的进度条和有关提取文件的文本。由于获取 .NET 安装程序的安装进度并不容易,因此我只是在安装执行期间向用户显示无尽的选取框进度条。
为此,将设置执行包装到如下代码中:
procedure InstallFramework;
var
StatusText: string;
begin
StatusText := WizardForm.StatusLabel.Caption;
WizardForm.StatusLabel.Caption := 'Installing .NET framework...';
WizardForm.ProgressGauge.Style := npbstMarquee;
try
{ here put the .NET setup execution code }
finally
WizardForm.StatusLabel.Caption := StatusText;
WizardForm.ProgressGauge.Style := npbstNormal;
end;
end;
这是 .NET 安装执行期间向导表单的样子(进度条是动画的):