Using Ngen

    I want to use Ngen for my application.
I have a batch file that calls ngen on all my dll's. I want to know whether
------------------------------------
ngen MyApplication.exe
ngen MyLib.dll
-----------------------------------

&

------------------------------------
ngen MyApplication.exe MyLib.dll
-------------------------------------

are equivalent



Answer this question

Using Ngen

  • Alessandro Molinari

    This is a great question.  First of all I'd like to point out that you are using the old syntax of NGen 1.0/1.1.  Because of this and other issues, we have revamped NGen syntax in version 2.0.  Note that while this syntax is still supported, we encourage everyone to move to the new syntax.

    ngen MyApplication.exe MyLib.dll

    will generate two ngen images, one for MyApplication.exe and one for MyLib.dll.  The ngen image for MyApplication will be identical to the one generated by

    ngen MyApplication.exe

    The ngen image for MyLib.dll may or may not be identical to the one generated by

    ngen MyLib.dll

    The case where they are different is when MyApplication.exe has a config file that will override the dependency bindings of MyLib.dll.  When loading MyLib.dll into the MyApplication.exe process, dependencies will be loaded according to the config file of the .exe.  If they are not the same as the ones loaded during ngen, we will not be able to use the ngen image.  This is why the ngen syntax allows you to specify multiple binaries in the command line.

    The new syntax for NGen has a flag /ExeConfig that allow you to explicitly specify the exe from which we will use the config file for computing dependencies.  This is a lot less confusing than this older syntax.

    A great resource for learning about the command line changes is the following MSDN magazine article:

    http://msdn.microsoft.com/msdnmag/issues/05/04/NGen/default.aspx

     

     


  • Using Ngen