在RUN命令节Inno Setup的错误HANDELING(忽略) [英] Inno setup error handeling (ignore) in RUN Section commands

查看:571
本文介绍了在RUN命令节Inno Setup的错误HANDELING(忽略)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .NET的DLL ,也可以是通过 RegAsm .NET注册3.5 .NET 4.5

我用这个codeS在我的设置脚本:

  [运行]
文件名:{dotnet40} \ RegAsm.exe;参数:my.dll; WorkingDir:{}的应用程序;标志:skipifdoesntexist; StatusMsg:注册控件。
文件名:{dotnet4064} \ RegAsm.exe;参数:my.dll; WorkingDir:{}的应用程序;标志:skipifdoesntexist; StatusMsg:注册控件。
文件名:{dotnet20} \ RegAsm.exe;参数:my.dll; WorkingDir:{}的应用程序;标志:skipifdoesntexist; StatusMsg:注册控件。
文件名:{dotnet2064} \ RegAsm.exe;参数:my.dll; WorkingDir:{}的应用程序;标志:skipifdoesntexist; StatusMsg:注册控件。
 

  • 在它运作良好,如果.NET 3.5和.NET 4.5安装在目标机器上
  • 我在我的脚本在 InitializeSet​​up 检查.NET函数。所以我知道其中一个版本,安装在系统上:V3.5 V4 V4.5

我们得到的错误在某些情况下是这样的:如果我们没有在目标机器上的.NET 3.5

我猜错误的原因是:

  

{dotnet20}

     

.NET Framework 2.0版的根目录。 {dotnet20}等价于{dotnet2032},除非安装在运行64位   模式,在这种情况下,它是相当于{dotnet2064}

     

一个将引发异常,如果试图扩大该常数,没有.NET Framework 2.0版present的系统上。

我的问题是如何处理而忽略这个异常和prevent设置回滚:

  

内部错误:找不到.NET Framework 2.0版

解决方案

如果你想坚持到 [运行] 部分,不要在脚本$写C $ C,那么我认为你没有太多可供选择的方案。将引发异常,每当一个常数不能扩展,这还只是这种情况下。唯一的选择我能想到的是添加检查函数,将试图扩大不变的的保护尝试。 。除块和prevent条目时,则会引发异常情况进行处理。喜欢的东西如下(根据您的code,缩短):

  [运行]
文件名:{dotnet20} \ RegAsm.exe;参数:File.dll;检查:RegAsmDotNet20Exists

[code]
功能RegAsmDotNet20Exists:布尔;
开始
  尝试
    //过程中的条目只有当目标二进制文件可以发现(等等
    //文件夹中恒可能已经适当扩大)
    结果:= FILEEXISTS(ExpandConstant({dotnet20} \ RegAsm.exe'));
  除
    //这是以防文件夹不断无法扩大了回退,
    检查是否二进制文件是当//或意想不到的事情发生
    //执行存在;在这种情况下,不处理输入
    结果:= FALSE;
  结束;
结束;
 

另外,相当清洁和更加安全的选择是单纯从做你的程序集注册在一些安装后的事件[code] 部分。即使你仍然需要使用这些常量时,捕获异常,你会得到更好地控制工具(例如,你可以得到出口code。如果这个工具使用它来得到一个错误的理由)。

I have a .net dll, it can be register by RegAsm .net 3.5 and .net 4.5

I use this codes in my setup script:

[Run]
Filename: "{dotnet40}\RegAsm.exe"; Parameters: "my.dll"; WorkingDir: "{app}"; Flags: skipifdoesntexist; StatusMsg: "Registering Controls."
Filename: "{dotnet4064}\RegAsm.exe"; Parameters: "my.dll"; WorkingDir: "{app}"; Flags: skipifdoesntexist; StatusMsg: "Registering Controls."
Filename: "{dotnet20}\RegAsm.exe"; Parameters: "my.dll"; WorkingDir: "{app}"; Flags: skipifdoesntexist; StatusMsg: "Registering Controls."
Filename: "{dotnet2064}\RegAsm.exe"; Parameters: "my.dll"; WorkingDir: "{app}"; Flags: skipifdoesntexist; StatusMsg: "Registering Controls."

  • It works well if .net 3.5 and .net 4.5 is installed on the target machine
  • I have a function in my script to checking .net in InitializeSetup. so i know one of these versions are installed on the system: v3.5 v4 v4.5

But

we get error in some cases like this: if we have not .net 3.5 on the target machine

I guess the error reason is:

{dotnet20}

.NET Framework version 2.0 root directory. {dotnet20} is equivalent to {dotnet2032} unless the install is running in 64-bit mode, in which case it is equivalent to {dotnet2064}.

An exception will be raised if an attempt is made to expand this constant on a system with no .NET Framework version 2.0 present.

My question is how can i handle and ignore this exception and prevent setup rollback:

Internal error: .Net Framework version 2.0 not found.

解决方案

If you want to stick to the [Run] section and do not write this in a scripting code, then I think you don't have many options to choose from. An exception is raised whenever a constant cannot be expanded, and that is just this case. The only option I can think of is adding a Check function that will attempt to expand the constant in a protected try..except block and prevent the entry to be processed when an exception is raised. Something like follows (based on your code, shortened):

[Run]
Filename: "{dotnet20}\RegAsm.exe"; Parameters: "File.dll"; Check: RegAsmDotNet20Exists

[Code]
function RegAsmDotNet20Exists: Boolean;
begin
  try
    // process the entry only if the target binary could be found (and so the
    // folder constant could have been properly expanded)
    Result := FileExists(ExpandConstant('{dotnet20}\RegAsm.exe'));
  except
    // this is the fallback in case the folder constant could not be expanded,
    // or something unexpected happened when checking if the binary file to be
    // executed exists; in such case, don't process the entry
    Result := False;
  end;
end;

Another, quite cleaner and a bit safer option would be doing your assembly registration purely from [Code] section in some of the postinstall events. Even though you'd still need to catch exceptions when using those constants, you would get more control over that tool (e.g. you could get the exit code to obtain an error reason if that tool uses it).

这篇关于在RUN命令节Inno Setup的错误HANDELING(忽略)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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