如何安装.NET框架使用InnoSetup编写一个prerequisite?框架、NET、prerequisite、InnoSetup

2023-09-02 01:44:35 作者:该用户已下线

我有类似这个的一个问题,但它似乎略有不同。

I have a question similar to this one, but it seems to be slightly different.

[Files]
Source: "dependenciesdotNetFx40_Full_x86_x64.exe"; DestDir: {tmp}; Flags: deleteafterinstall; Check: FrameworkIsNotInstalled
Source: "C:WindowsMicrosoft.NETassemblyGAC_MSILMySql.Datav4.0_6.5.4.0__c5687fc88969c44dMySql.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, 'SoftwareMicrosoft.NETFrameworkpolicyv4.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?

推荐答案

由于 [运行] 部分后, [文件]处理部分,这自然是不可能与你中的脚本(因此你的问题)做到这一点。有几种方法,其中一个我建议是执行从AfterInstall设置条目本身的参数功能。所以,你会删除当前 [运行] 部分,然后写一个脚本是这样的:

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: "dependenciesdotNetFx40_Full_x86_x64.exe"; DestDir: {tmp}; Flags: deleteafterinstall; AfterInstall: InstallFramework; Check: FrameworkIsNotInstalled
Source: "C:WindowsMicrosoft.NETassemblyGAC_MSILMySql.Datav4.0_6.5.4.0__c5687fc88969c44dMySql.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;

这个过程很简单,如果检查 [文件] 部分的.NET设置项功能计算结果为真( FrameworkIsNotInstalled ),该条目被处理,这拷贝安装二进制进入创新安装的临时文件夹,如果成功,则 AfterInstall 函数 InstallFramework 后立即被调用。在这个功能中,.NET安装手动调用 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.

最后,如果所有这一切成功,安装继续处理下一个 [文件] 部分条目,这是你的程序集,是要进行登记。现在,随着安装了.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.

要做到这裹安装程序执行到code是这样的:

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):