.netwixvstongenaddin-express

Using NGen with Wix Toolset for AddIn Express Excel Addin


I would like to improve the first-run performance of a .NET Excel Addin developed using AddIn Express.

The reason the addin runs slowly during the first execution of various tasks is because the JIT spends time converting MSIL into native executable machine code.

The standard approach to remedy this is to run NGen on your assembly from your installer to pre-generate the native code.

I use Wix Toolset for my installer and have tried getting things set up properly, but I am still not getting rid of the slow initial execution problem so I am wondering if there is something specific I need to do to get this working with Addin Express Excel Addins. My addin installs to the %LocalAppData% folder just in case that info is important.

I followed the guides here: http://wixtoolset.org/documentation/manual/v3/howtos/files_and_registry/ngen_managed_assemblies.html http://wixtoolset.org/documentation/manual/v3/xsd/netfx/nativeimage.html

and have something like this in my Wix xml:

<netfx:NativeImage Id="ngen_MyExcelAddin.dll" Platform="all" Priority="0" AppBaseDirectory="TARGETDIR" />

My installer builds fine and installs fine, but the slow initial execution problem does not go away leading me to believe that it is still using the JIT. My initial thought was that I may need to specify the AssemblyApplication property, but I have tried setting that to various AddinExpress dlls(adxloader64.dll, adxloader.dll, AddinExpress.XL.2005.dll, AddinExpress.MSO.2005.dll) to no success. Any help would be greatly appreciated.


Solution

  • After reading some comments on other forums, it seems that NGen would have required an installer that required Administrator rights and also that the dlls needed to be installed in the GAC. My installer is for the current user and does not require administrator access so it didn't fit to use NGen.

    Instead I did something similar by pre-compiling most of the methods in a background thread when the addin is first loaded using the code from this link: http://www.codeproject.com/Articles/31316/Pre-compile-pre-JIT-your-assembly-on-the-fly-or-tr