Call ngen from an NSIS installer

I am using NSIS to deploy a .Net application. The install / uninstall process works fine, but I would like to add the final ngen step to improve startup performance.

Unfortunately, Google did not disclose any relevant material. It is unlikely that no one has ever done this before - maybe someone has an idea?

In the unlikely event that this cannot be supported without ugly hacks, I would like to use another installation technology provided that can run on my Linux build server. (This, for example, excludes WiX.)

Any ideas?

+4
source share
3 answers

You can execute ngen in your last section using the built-in Exec / ExecWait commands (alternatively, use nsExec or one of the third-party exec plugins)

ExecWait '"ngen.exe" install "c:\path\to\your\assembly" /silent' 

Note: this assumes that ngen is located in a path or current directory, which is probably not on most systems, so either set the current directory using SetOutPath or use the full path to ngen

You must figure out which switches you need yourself, see the MSDN for 2.0 and 1.x ngen documentation

+1
source

NGen will be in the .NET framework directory, for example:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

Option 1 - GetCORSystemDirectory () is a sytem API call that you can use to get the .NET Framework directory, but the problem is that it is like reading the documentation you need to call from a. NET Thus, you can run a small .NET application and write the result of GetCORSystemDirectory () to an ini file. Perhaps find this feature and see if you can find anything useful through Google.

Option 2 - you can guess the .NET platform in the expected path and iterate through the directories and find the one that starts with "v2.0."

Option 3 - Just extract ngen from your isntaller and then run it. This is what I did with regasm on occasion. I am not sure what side effects you may encounter, whether it is completely legal, or if there are other files that it depends on. If this is something like regasm.exe, you should be fine while the .NET platform is already installed.

+3
source

There seems to be a way to get the execution directory via nsis: http://nsis.sourceforge.net/Get_directory_of_installed_.NET_runtime

Once the path is known, all that remains is to call ngen with the correct parameters. Excellent!

0
source

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


All Articles