如何使用Inno Setup安装.NET Framework作为先决条件? [英] How can I install .NET framework as a prerequisite using Inno Setup?

查看:410
本文介绍了如何使用Inno Setup安装.NET Framework作为先决条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与 Inno Setup相似的问题:确认已安装.NET 4.0 ,但似乎有点不同。

I have a question similar to Inno Setup: Verify that .NET 4.0 is installed, but it seems to be slightly different.

[Files]
Source: "dependencies\dotNetFx40_Full_x86_x64.exe"; DestDir: {tmp}; Flags: deleteafterinstall; 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"

[Run]
Filename: {tmp}\dotNetFx40_Full_x86_x64.exe; Description: Install Microsoft .NET Framework 4.0; Parameters: /q /norestart; Check: FrameworkIsNotInstalled

[code]
function FrameworkIsNotInstalled: Boolean;
begin
  Result := not RegKeyExists(HKEY_LOCAL_MACHINE, 'Software\Microsoft\.NETFramework\policy\v4.0');
end;

如您所见,我正在尝试向GAC注册文件。不幸的是,在某些计算机上,可能没有 安装.NET框架。所以我需要先安装它。无论如何,在我尝试注册文件之前,是否可以强制安装.NET运行时

As you can see, I'm trying to register a file with the GAC. Unfortunately on some machines it's possible that the .NET framework is not installed. So I need to install it first. Is there anyway that I can force an installation of the .NET runtime before I try to register my files?

推荐答案

由于 [Run] 部分在 [Files] 部分之后进行处理,因此自然不可能使用您显示的脚本来执行此操作(因此,您会提出问题)。我建议的几种方法是从 <$ c $设置条目本身的c> AfterInstall 参数功能。因此,您将删除当前的 [Run] 部分,并编写如下脚本:

Since the [Run] section is processed after the [Files] section, it is naturally impossible to do it with the script you've shown (hence your question). There are few ways where the one I would recommend is to execute the .NET setup from the AfterInstall parameter function of the setup entry itself. So you would remove your current [Run] section and write a script like this:

[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设置项的功能评估为True( FrameworkIsNotInstalled ),将处理该条目,将安装程序二进制文件复制到Inno Setup的临时文件夹中,如果成功,则将 AfterInstall 函数 InstallFramework 之后立即被调用。在此函数内部,通过调用 Exec 函数。

The process is easy, if the Check function of the .NET setup entry of the [Files] section evaluates to True (FrameworkIsNotInstalled), the entry is processed, which copies the setup binary into the Inno Setup's temporary folder and if that succeeds, the AfterInstall function InstallFramework is called immediately after. Inside of this function, the .NET setup is manually executed by calling Exec function.

最后,如果所有操作成功,安装将继续处理下一个 [Files] 节条目,这是将要注册的程序集。现在,使用已安装的.NET框架。因此,如您所见, [文件] 部分的顺序在这里至关重要。

And finally, if all of that succeeds, the installation continues to process the next [Files] section entry, which is your assembly that is going to be registered. Now, with the installed .NET framework. So as you can see, the order of the [Files] section entries is crucial here.

您在注释中还询问了如何向用户显示一些进度,因为按照我在此处发布的方式执行.NET设置会阻止 [文件] 条目,从而显示停止的进度条和有关提取文件的文本。由于要获得.NET安装程序的安装进度并不容易,因此我将向用户显示在执行安装过程中无休止的字幕进度条。

You've additionally asked in your comment, how to show to the user some progress, since executing the .NET setup in the way I've posted here blocks the [Files] entry, which leads to showing the stopped progress bar and text about extracting files. Since it wouldn't be easy to get the .NET setup's installation progress, I would simply show to the user endless marquee progress bar during that setup execution.

将执行设置包装成这样的代码:

To do this wrap that setup execution into a code like this:

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设置过程中向导表单的样子(进度条是动画的) :

This is how the wizard form looks like during that .NET setup execution (the progress bar is animated):

这篇关于如何使用Inno Setup安装.NET Framework作为先决条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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