-----------------------------------------------------------
New Message on MumbaiUserGroup
-----------------------------------------------------------
From: Nasha
Message 2 in Discussion
New Message on MumbaiUserGroup
Artricle:Ngen.exe -- A discussion -- Some Queries (.NET Framework Tools
Series)
Reply
Reply to Sender
Recommend
Message 1 in Discussion
From:
Nasha
Hi Guys,
Today we will discuss Ngen.exe and then there are some questions regarding Ngen
which ahve always bothered me. I have managed to get answers to them ....
please read thru and let me know your answers to them ... coz I am sure these
questions must have bothered u also.
Lets start with the discussion ....
This tool is used to create a native Image from an .NET assembly and installs
it into the native image cache on that computer. Since assembly image is
present on the local machine cache loading of the assembly becomes faster
because .NET reads data from the native image than generating them dynamically
(JIT).
This tool is available at :
<drive>:\WINNT\Microsoft.NET\Framework\<version>\ngen.exe
Lets us check out all the options of Native Image Gernerator.
1) Go to the Visual Studio command prompt and type
Ngen.exe /help // this will show us all options
2) You will see the below details
Administrative options:
/show Show existing native images (show all if no args)
/delete Delete existing native images (delete all if no args)
Developer options:
/debug Generate image which can be used under a debugger
/debugopt Generate image which can be used under a debugger
in optimized debugging mode
/prof Generate image which can be used under a profiler
Miscellaneous options:
/? or /help Show this message
/nologo Prevents displaying of logo
/silent Prevents displaying of success messages
Usage : ngen [options] <assembly path or display name>
The native Image contains compiled processor-specific machine code.If you
create an native image of an assembly then .NET
Runtime tries to look out for that assembly. If it is unable to find the
assembly than it reverts back to JIT.
Incase the application is running in a debug mode than .NET runtime looks for a
native image created with /debug or /debugopt option.
Note: The assembly image created by Ngen depends on the options that we specify
and below computer settings like: <DIR>
The CPU type.
The version of the operating system.
The exact identity of the assembly (recompilation changes identity).
The exact identity of all assemblies that the assembly references.
Security factors. </DIR>
To view all the native Images installed on the a machine go to:
<drive>\<windows folder> say Winnt\assembly
In the assembly folder (GAC) sort on type and you will find all the native
Images installed on that machine.
There are few questions that I have always had in my mind regarding Ngen and
the assembly images:
1) How long are these native assembly images valid ?
Since the native assembly image is machine specific its validity depends on all
the above factors. Well the are number of scenarios when the native image can
become invalid : <DIR>
.NET Framework updation causes all native images to become invalid.
Computer CPU updation
Any Changes made to the OS.
Recompilation of an assembly to IL causes existing native images of
that assembly to become invalid.
Recompliation of a referenced assembly causes the native image to the
refrencing assembly to become invalid.
Change in machine security policy.</DIR>
Hence if there is any change in the computer setting or environment then there
are chances of the Native Image becoming invalid.
Note : Its just that the assembly native image has become invalid not the
assembly. hence next time the assembly will be loaded with (JIT) its native
image will not be loaded.
2) Can you create a native Image of ASP.NET assembly ... does this work ... is
it possible ????
Native Image generator creates a local image of an .NET Assembly and installs
that image in the native cache on the local machine. But when you create a
Native Image of an ASP.NET assembly the .NET Runtime ignores that assembly and
reverts back to JIT. This is because CLR cannot load native images in a shared
application domain and all ASP.NET applications run in a shared application
domain. Hence although the native image of the assembly will be created it will
not be installed in the image cache.
3) How do I run Ngen as a part of Installation or deloyment of the application
?
To run Ngen as a part of your application deployment or setup create a custom
action during installation which will run the ngen and create images for all
your application assemblies. Similarly also create a custom action in you
deployment project during uninstallation to remove them from the native cache.
These were questions that I had in my mind ... if u have any other let griup
know .... if u have more thought opinions about these questions pls post them.
Going ahead lets just explore a few options of Ngen.exe
To create a native assembly
ngen <Assembly name with its full path>
You can also create a native images of one or more assemblies at the same time
ngen <assembly1> <assembly3> <assembly2> <assembly4>
To view all the assemblies in the native cache use the/show option
ngen /show
To delete an assembly from the cache
ngen /delete <assembly name>
-- Please post your queries and comments for my articles in the usergroup for
the benefit of all. I hope this step from my end is helpful to all of us.
Regards,
Namratha (Nasha)
View other groups in this category.
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/mumbaiusergroup/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you
received this message by mistake, please click the "Remove" link below. On the
pre-addressed e-mail message that opens, simply click "Send". Your e-mail
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]