如何在安装过程中正确安装 NGen .NET 应用程序

发布于 2024-10-09 08:31:37 字数 3644 浏览 0 评论 0原文

我正在使用 Inno Setup 为我的应用程序生成安装程序,并且我想在安装过程中为 NGen 我的应用程序编写一个脚本。我希望代码能够将 NGen 文件定位到 x86x64AnyCPU。我希望能够在 32 位64 位 系统上NGen。我怎样才能实现这个目标?

我找到了一些有用的链接:
获取 .NET Framework 目录路径
http://nsis.sourceforge.net/Get_directory_of_installed_.NET_runtime
我发现这是一个相当复杂的问题 - 最多可以有 4 个不同版本的 NGen 应用程序:

  1. 对于 CLR 2.0 和 32 位系统
  2. 对于 CLR 2.0 和 64 位系统
  3. CLR 4.0 和 32 位系统
  4. 对于 CLR 4.0 和 64 位系统

更复杂的是,应用程序可以针对 32 位 CPU 并在 64 位系统上运行。


所以我想到的是一个看起来像这样的函数:

function NGenFile(file: String; targetCPU: TTargetCPU; targetCLR: TTargetCLR): Boolean;

并在成功安装后在 [Code] 中的某个地方调用它:

NGenFile(ExpandConstant('{app}\application.exe'), tcpu64, tclr20);
NGenFile(ExpandConstant('{app}\library1.dll'), tcpu64, tclr40);
NGenFile(ExpandConstant('{app}\library2.dll'), tcpu32, tclr20);
NGenFile(ExpandConstant('{app}\library3.dll'), tcpu32, tclr40);
NGenFile(ExpandConstant('{app}\library4.dll'), tcpuAny, tclr20);
NGenFile(ExpandConstant('{app}\library5.dll'), tcpuAny, tclr40);

它会像这样工作:

  1. application.exe(tcpu64,tclr20)
    在 64 位系统上,它将生成针对 64 位 CPU 和 CLR 2.0 的本机映像,结果 := True
    在 32 位系统上它不会执行任何操作,结果 := False

  2. library1.dll (tcpu64, tclr40)
    在 64 位系统上,它将生成针对 64 位 CPU 和 CLR 4.0 的本机映像,结果 := True
    在 32 位系统上它不会执行任何操作,结果 := False

  3. library2.dll (tcpu32, tclr20)
    在 64 位系统上,它将生成针对 32 位 CPU 和 CLR 2.0 的本机映像,结果 := True
    在 32 位系统上,它会执行与 64 位系统相同的操作

  4. library3.dll(tcpu32、tclr40)
    在 64 位系统上,它将生成针对 32 位 CPU 和 CLR 4.0 的本机映像,结果 := True
    在 32 位系统上,它会执行与 64 位系统相同的操作

  5. library4.dll(tcpuAny、tclr20)
    在 64 位系统上,它将生成针对 64 位 CPU 和 CLR 2.0 的本机映像,结果 := True
    在 32 位系统上,它将生成针对 32 位 CPU 和 CLR 2.0 的本机映像,结果 := True

  6. library5.dll (tcpuAny, tclr40)
    在 64 位系统上,它将生成针对 64 位 CPU 和 CLR 4.0 的本机映像,结果 := True
    在 32 位系统上,它将生成针对 32 位 CPU 和 CLR 4.0 的本机映像,结果 := True


因此,为了使其工作,我需要知道 .NET 运行时目录的 4 个不同路径。这是我发现的:

  1. 32位系统 CLR 2.0
    获取“HKLM\Software\Microsoft\.NETFramework”中“InstallRoot”的值,保存到value1
    获取“HKLM\Software\Microsoft\.NETFramework\Policy\v2.0”中第一个值的名称,保存到 value2
    值1 +“v2.0”。 + value2 + "\ngen.exe" =>赢
    示例:“c:\Windows\Microsoft.NET\Framework\v2.0.50727\ngen.exe”
    我认为这在 32 位和 64 位系统上的工作方式相同

  2. 32 位系统 CLR 4.0
    获取“HKLM\Software\Microsoft\.NETFramework”中“InstallRoot”的值,保存到value1
    获取“HKLM\Software\Microsoft\.NETFramework\Policy\v4.0”中第一个值的名称,保存到 value2
    值1 +“v4.0”。 + value2 + "\ngen.exe" =>赢
    示例:“c:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe”
    我认为这在 32 位和 64 位系统上的工作方式相同

  3. 64 位系统 CLR 2.0
    如何获取 64 位 .NET Framework 的 InstallRoot?
    示例:“c:\Windows\Microsoft.NET\Framework64\v2.0.50727\ngen.exe”

  4. 64 位系统 CLR 4.0
    如何获取 64 位 .NET Framework 的 InstallRoot?
    示例:“c:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe”

我实际上不确定 64 位系统上的“InstallRoot”值是否会指向 32 位 .NET 或 64 位 .NET 的 InstallRoot ,那么前两种方法对于任何系统都可靠吗?第二种方法看起来怎么样?有没有更简单的方法来实现这一切?

I'm using Inno Setup to generate setup program for my application, and I would like to write a script to NGen my application during installation. I want the code to be able to NGen files targeting x86, x64, or AnyCPU. I want to be able to NGen on 32bit and 64bit systems. How can I achieve this?

I've found a couple of helpful links:
Getting the .NET Framework directory path
http://nsis.sourceforge.net/Get_directory_of_installed_.NET_runtime
Where I've found it is a quite complex problem - there can be up to 4 different versions of NGen application:

  1. for CLR 2.0 and 32bit systems
  2. for CLR 2.0 and 64bit systems
  3. for CLR 4.0 and 32bit systems
  4. for CLR 4.0 and 64bit systems

And it is even more complicated by the fact the application can target 32bit CPU and run on 64bit system.


So what came to my mind was a function looking like this:

function NGenFile(file: String; targetCPU: TTargetCPU; targetCLR: TTargetCLR): Boolean;

and call it somewhere in [Code] after successful isntallation:

NGenFile(ExpandConstant('{app}\application.exe'), tcpu64, tclr20);
NGenFile(ExpandConstant('{app}\library1.dll'), tcpu64, tclr40);
NGenFile(ExpandConstant('{app}\library2.dll'), tcpu32, tclr20);
NGenFile(ExpandConstant('{app}\library3.dll'), tcpu32, tclr40);
NGenFile(ExpandConstant('{app}\library4.dll'), tcpuAny, tclr20);
NGenFile(ExpandConstant('{app}\library5.dll'), tcpuAny, tclr40);

And it would work like this:

  1. application.exe (tcpu64, tclr20)
    On 64bit system it would generate native image targeting 64bit CPU and CLR 2.0, Result := True
    On 32bit system it wouldn't do anything, Result := False

  2. library1.dll (tcpu64, tclr40)
    On 64bit system it would generate native image targeting 64bit CPU and CLR 4.0, Result := True
    On 32bit system it wouldn't do anything, Result := False

  3. library2.dll (tcpu32, tclr20)
    On 64bit system it would generate native image targeting 32bit CPU and CLR 2.0, Result := True
    On 32bit system it would do the same as on 64bit system

  4. library3.dll (tcpu32, tclr40)
    On 64bit system it would generate native image targeting 32bit CPU and CLR 4.0, Result := True
    On 32bit system it would do the same as on 64bit system

  5. library4.dll (tcpuAny, tclr20)
    On 64bit system it would generate native image targeting 64bit CPU and CLR 2.0, Result := True
    On 32bit system it would generate native image targeting 32bit CPU and CLR 2.0, Result := True

  6. library5.dll (tcpuAny, tclr40)
    On 64bit system it would generate native image targeting 64bit CPU and CLR 4.0, Result := True
    On 32bit system it would generate native image targeting 32bit CPU and CLR 4.0, Result := True


So to make it work, I need to know 4 different paths to .NET runtime directory. This is what I've found:

  1. 32bit system CLR 2.0
    Get value of "InstallRoot" in "HKLM\Software\Microsoft\.NETFramework", save to value1
    Get name of first value in "HKLM\Software\Microsoft\.NETFramework\Policy\v2.0", save to value2
    value1 + "v2.0." + value2 + "\ngen.exe" => win
    Example: "c:\Windows\Microsoft.NET\Framework\v2.0.50727\ngen.exe"
    I assume this will work the same on 32bit and 64bit systems

  2. 32bit system CLR 4.0
    Get value of "InstallRoot" in "HKLM\Software\Microsoft\.NETFramework", save to value1
    Get name of first value in "HKLM\Software\Microsoft\.NETFramework\Policy\v4.0", save to value2
    value1 + "v4.0." + value2 + "\ngen.exe" => win
    Example: "c:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe"
    I assume this will work the same on 32bit and 64bit systems

  3. 64bit system CLR 2.0
    How to get InstallRoot for 64bit .NET Framework?
    Example: "c:\Windows\Microsoft.NET\Framework64\v2.0.50727\ngen.exe"

  4. 64bit system CLR 4.0
    How to get InstallRoot for 64bit .NET Framework?
    Example: "c:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe"

I'm actually not sure if the "InstallRoot" value on 64bit systems would point to InstallRoot of 32bit .NET, or 64bit .NET, so are the first 2 methods reliable for any system? And how would look like the second 2 methods? Is there any simpler way to achieve all of this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毁梦 2024-10-16 08:31:37

您使用的 InnoSetup 版本是什么?在我使用的版本(5.4.0a)中,已经有用于查找.NET根目录的常量。来自 InnoSetup 帮助:

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

如果尝试扩展此内容,将会引发异常
在不存在 .NET Framework 2.0 版的系统上常量。

{dotnet2032} 32 位 .NET Framework 版本 2.0 根目录。

如果尝试扩展此内容,将会引发异常
在不存在 .NET Framework 2.0 版的系统上常量。

{dotnet2064} 仅限 64 位 Windows:64 位 .NET Framework 版本 2.0
根目录。

如果尝试扩展此内容,将会引发异常
在不存在 .NET Framework 2.0 版的系统上常量。

{dotnet40} .NET Framework 版本 4.0 根目录。 {dotnet40} 是
相当于 {dotnet4032},除非安装在 64 位中运行
模式,在这种情况下它相当于 {dotnet4064}。

如果尝试扩展此内容,将会引发异常
在没有 .NET Framework 4.0 版本的系统上常量。

{dotnet4032} 32 位 .NET Framework 版本 4.0 根目录。

如果尝试扩展此内容,将会引发异常
在没有 .NET Framework 4.0 版本的系统上常量。

{dotnet4064} 仅限 64 位 Windows:64 位 .NET Framework 版本 4.0
根目录。

如果尝试扩展此内容,将会引发异常
在没有 .NET Framework 4.0 版本的系统上常量。

What version of InnoSetup are you using? In the version I use (5.4.0a), there are already constants for to find the .NET root directory. From the InnoSetup help:

{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.

{dotnet2032} 32-bit .NET Framework version 2.0 root directory.

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.

{dotnet2064} 64-bit Windows only: 64-bit .NET Framework version 2.0
root directory.

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.

{dotnet40} .NET Framework version 4.0 root directory. {dotnet40} is
equivalent to {dotnet4032} unless the install is running in 64-bit
mode, in which case it is equivalent to {dotnet4064}.

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

{dotnet4032} 32-bit .NET Framework version 4.0 root directory.

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

{dotnet4064} 64-bit Windows only: 64-bit .NET Framework version 4.0
root directory.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文