Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to properly NGen .NET application during installation
    primarykey
    data
    text
    <p>I'm using <code>Inno Setup</code> to generate setup program for my application, and I would like to write a script to <strong>NGen</strong> my application during installation. I want the code to be able to <strong>NGen</strong> files targeting <code>x86</code>, <code>x64</code>, or <code>AnyCPU</code>. I want to be able to <strong>NGen</strong> on <code>32bit</code> and <code>64bit</code> systems. How can I achieve this?</p> <p>I've found a couple of helpful links:<br> <a href="https://stackoverflow.com/questions/375860/getting-the-net-framework-directory-path">Getting the .NET Framework directory path</a><br> <a href="http://nsis.sourceforge.net/Get_directory_of_installed_.NET_runtime" rel="nofollow noreferrer">http://nsis.sourceforge.net/Get_directory_of_installed_.NET_runtime</a><br> Where I've found it is a quite complex problem - there can be up to 4 different versions of <strong>NGen</strong> application:</p> <ol> <li>for CLR 2.0 and 32bit systems</li> <li>for CLR 2.0 and 64bit systems</li> <li>for CLR 4.0 and 32bit systems</li> <li>for CLR 4.0 and 64bit systems</li> </ol> <p>And it is even more complicated by the fact the application can target 32bit CPU and run on 64bit system. </p> <hr> <p>So what came to my mind was a function looking like this:</p> <pre><code>function NGenFile(file: String; targetCPU: TTargetCPU; targetCLR: TTargetCLR): Boolean; </code></pre> <p>and call it somewhere in <code>[Code]</code> after successful isntallation:</p> <pre><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); </code></pre> <p>And it would work like this:</p> <ol> <li><p><strong>application.exe</strong> (tcpu64, tclr20)<br> On 64bit system it would generate native image targeting 64bit CPU and CLR 2.0, Result := True<br> On 32bit system it wouldn't do anything, Result := False</p></li> <li><p><strong>library1.dll</strong> (tcpu64, tclr40)<br> On 64bit system it would generate native image targeting 64bit CPU and CLR 4.0, Result := True<br> On 32bit system it wouldn't do anything, Result := False</p></li> <li><p><strong>library2.dll</strong> (tcpu32, tclr20)<br> On 64bit system it would generate native image targeting 32bit CPU and CLR 2.0, Result := True<br> On 32bit system it would do the same as on 64bit system</p></li> <li><p><strong>library3.dll</strong> (tcpu32, tclr40)<br> On 64bit system it would generate native image targeting 32bit CPU and CLR 4.0, Result := True<br> On 32bit system it would do the same as on 64bit system</p></li> <li><p><strong>library4.dll</strong> (tcpuAny, tclr20)<br> On 64bit system it would generate native image targeting 64bit CPU and CLR 2.0, Result := True<br> On 32bit system it would generate native image targeting 32bit CPU and CLR 2.0, Result := True</p></li> <li><p><strong>library5.dll</strong> (tcpuAny, tclr40)<br> On 64bit system it would generate native image targeting 64bit CPU and CLR 4.0, Result := True<br> On 32bit system it would generate native image targeting 32bit CPU and CLR 4.0, Result := True</p></li> </ol> <hr> <p>So to make it work, I need to know 4 different paths to .NET runtime directory. This is what I've found:</p> <ol> <li><p><strong>32bit system CLR 2.0</strong><br> Get value of "InstallRoot" in "HKLM\Software\Microsoft\.NETFramework", save to value1<br> Get name of first value in "HKLM\Software\Microsoft\.NETFramework\Policy\v2.0", save to value2<br> value1 + "v2.0." + value2 + "\ngen.exe" => win<br> Example: "c:\Windows\Microsoft.NET\Framework\v2.0.50727\ngen.exe"<br> I assume this will work the same on 32bit and 64bit systems</p></li> <li><p><strong>32bit system CLR 4.0</strong><br> Get value of "InstallRoot" in "HKLM\Software\Microsoft\.NETFramework", save to value1<br> Get name of first value in "HKLM\Software\Microsoft\.NETFramework\Policy\v4.0", save to value2<br> value1 + "v4.0." + value2 + "\ngen.exe" => win<br> Example: "c:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe"<br> I assume this will work the same on 32bit and 64bit systems</p></li> <li><p><strong>64bit system CLR 2.0</strong><br> How to get InstallRoot for 64bit .NET Framework?<br> Example: "c:\Windows\Microsoft.NET\Framework64\v2.0.50727\ngen.exe"</p></li> <li><p><strong>64bit system CLR 4.0</strong><br> How to get InstallRoot for 64bit .NET Framework?<br> Example: "c:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe"</p></li> </ol> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload