Using a Script to NGEN an Assembly
The message - "Creating .NET Native Executable Images..." - that appears during installation of Alintex Script .NET, has generated a lot of questions from users. Some are hopeful, that it means that one can compile a .NET application to native code, while others just want to know how the installer does it.
The .NET native image generator (NGEN) application, which is installed either as part of the .NET runtime (redistributable) or the SDK (Framework), installs a native image to the native image cache which improves application startup time. It does so by precompiling code which would otherwise be compiled just-in-time.
In an application like Alintex Script, which spends a large proportion of it's execution time loading, and is typically run many times for short periods, it has a significant effect on performance. However, for a normal application, the inability for the compiler to compile just-in-time can impact on performance. It should be noted, however, that future .NET releases will diminish that disadvantage.
A couple of points to highlight, are that NGEN needs to be run against an assembly on the end users system (typically during installation). Doing so does not eliminate the need for the original assembly - one uses the original assembly as normal. The runtime automatically determines whether or not a native image exists in the cache and if it should be used.
How does the Alintex Script installer do it?
It's probably no surprise that it does so by running a script.
The script in question is called ngen.psf and internally consists of three script files - ngen.csx, application.cs and fileInputBox.cs. In this case they are all C# language files, but any one of them could be in any supported language. The script's Portable Script File Description can be viewed in your web browser.
The installer runs the script using the /unattended command line option so no output is reported to the user, however the script can also be run by specifying a file on the command line, or by double-clicking on the ngen.psf icon.
The script is available for download at http://www.alintex.com/scriptdetail.aspx?script=ngen.psf