How to use NGen.NET app correctly during installation

I use Inno Setupto create an installer for my application, and I would like to write a script to NGen application during installation. I want the code to be able to NGen to target files x86, x64or AnyCPU. I want to be able to NGen in 32bitand systems 64bit. How can I achieve this?

I found a couple of useful links:
Getting the path to the .NET Framework directory
http://nsis.sourceforge.net/Get_directory_of_installed_.NET_runtime
Where I found this rather complicated problem - there can be up to 4 different versions of the NGen application :

  • for CLR 2.0 and 32-bit systems.
  • for CLR 2.0 and 64bit systems
  • for CLR 4.0 and 32bit systems
  • for CLR 4.0 and 64-bit systems.

And this is further complicated by the fact that the application can focus on a 32-bit processor and run on a 64-bit system.


So, what occurred to me was a function that looked like this:

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

and call it somewhere in [Code]after a 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 will work as follows:

  • application.exe (tcpu64, tclr20)
    On a 64-bit system, it will generate its own graphic targeting on a 64-bit processor and CLR 2.0, Result: = True
    On a 32-bit system, nothing will work, Result: = False

  • library1.dll (tcpu64, tclr40)
    64- 64- CLR 4.0, : = True
    32- , : = False

  • library2.dll (tcpu32, tclr20)
    64- 32- CLR 2.0, : = True
    32- , 64-

  • library3.dll (tcpu32, tclr40)
    64- 32- CLR 4.0, : = True
    32- , 64-

  • library4.dll (tcpuAny, tclr20)
    64- 64- CLR 2.0, : = True
    32- 32- CLR 2.0, : = True

  • library5.dll (tcpuAny, tclr40)
    64- 64- CLR 4.0, : = True
    32- 32- CLR 4.0, : = True


, , 4 .NET. , :

  • 32- CLR 2.0
    "InstallRoot" "HKLM\Software\Microsoft \.NETFramework", value1
    "HKLM\Software\Microsoft \.NETFramework\Policy\v2.0", value2
    value1 + "v2.0." + value2 + "\ngen.exe" = >
    : "c:\Windows\Microsoft.NET\Framework\v2.0.50727\ngen.exe"
    , 32- 64- .

  • 32- CLR 4.0
    "InstallRoot" "HKLM\Software\Microsoft \.NETFramework", value1
    "HKLM\Software\Microsoft \.NETFramework\Policy\v4.0", value2
    value1 + "v4.0." + value2 + "\ngen.exe" = >
    : "c:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe"
    , 32- 64- .

  • 64- CLR 2.0
    InstallRoot 64- .NET Framework?
    : "c:\Windows\Microsoft.NET\Framework64\v2.0.50727\ngen.exe"

  • 64- CLR 4.0
    InstallRoot 64- .NET Framework?
    : "c:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe"

, "InstallRoot" 64- InstallRoot 32- .NET 64- .NET, 2 ? 2 ? ?

+3
1

InnoSetup ? , (5.4.0a), .NET. InnoSetup:

{dotnet20} .NET Framework 2.0. {dotnet20} {dotnet2032}, 64- mode, {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- mode, {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.

+3

Source: https://habr.com/ru/post/1782690/


All Articles