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 ? ?