tags:

views:

185

answers:

3

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

Unfortunately, Google didn't reveal any relevant material. It's unlikely that noone has ever done this before - maybe someone here has some idea?

In the unlikely case that this is impossible to support without ugly hacks, I would be willing to use a different installer technology provided it can run on my Linux build server. (This rules out WiX, for example.)

Any ideas?

+1  A: 

You could execute ngen in your last section using the built in Exec/ExecWait commands (Alternatively, use nsExec or one of the 3rd party exec plugins)

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

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

You have to figure out the exact switches you need on your own, see MSDN for 2.0 and 1.x ngen documentation

Anders
"Note: this assumes that ngen is in the path or current directory which it probably is not on most systems, so either set the current directory with SetOutPath or use a full path to ngen"That's the issue, actually, I cannot find a reliable way to invoke ngen. Maybe this is information is available somewhere in the registry?
BlackStar
Thanks! Your post, along with the post below (on the NGen path) has led me to a working solution.
BlackStar
@BlackStar: Could you add your working solution to the end of your question? Or, even better, add it to the wiki at http://nsis.sourceforge.net and link to it in your question? You're not the only one would'd like to run ngen from an NSIS installer. :-)
Daniel Stutzbach
+1  A: 

NGen will be in the .NET framework directory such as:

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

Option 1 - GetCORSystemDirectory() is a sytem API call that you can use to get the directory of the .NET Framework, but the problem here is that it sounds like from reading the documentation that it needs to be called from a .NET application. So you could run a tiny .NET application and have it write the result of GetCORSystemDirectory() to a ini file. Maybe search for that function and see if you find anything useful through google.

Option 2 - You could assume the .NET framework in in the expected path and iterate through the directorys and find one that starts with "v2.0.".

Option 3 - Simply extract ngen from your isntaller and then run it. This is what I've done with regasm on occasion. I'm not sure what side effects you might encounter, whether this is completely legal, or if there are any other files it depends on. If it's anything like regasm.exe, you should be fine as long as the .NET framework is already installed.

AaronLS
Thanks! Seems there is a ready-made solution for getting the runtime: http://nsis.sourceforge.net/Get_directory_of_installed_.NET_runtime
BlackStar
A: 

Seems there is a way to get the runtime directory through nsis: http://nsis.sourceforge.net/Get_directory_of_installed_.NET_runtime

Once the path is known, all that's left is calling ngen with the correct parameters. Great!

BlackStar