15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

shared assemblies ❘ 451<br />

Now, the assembly is in the GAC only once, but it has two references. To delete the assembly from the GAC,<br />

both references must be removed:<br />

gacutil /u shareddemo /r OPAQUE 4711 "Opaque installation"<br />

gacutil /u shareddemo /r FILEPATH c:\ProCSharp\Assemblies\Client "Shared Demo"<br />

To remove a shared assembly, the option /u requires the assembly name without the fi le<br />

extension DLL. On the contrary, the option /i to install a shared assembly requires the<br />

complete fi lename including the fi le extension.<br />

Chapter 17 deals with deployment of assemblies, where the reference count is being<br />

dealt with in an MSI package.<br />

native image generator<br />

With the native image generator, Ngen.exe , you can compile the IL code to native code at installation<br />

time. This way the program can start faster because the compilation during runtime is no longer necessary.<br />

Comparing precompiled assemblies to assemblies where the JIT compiler needs to run is not different from<br />

a performance view after the IL code is compiled. The only improvement you get with the native image<br />

generator is that the application starts faster because there ’ s no need to run JIT. Reducing the startup time<br />

of the application might be enough reason for using the native image generator. In case you create a native<br />

image from the executable, you should also create native images from all the DLLs that are loaded by<br />

the executable. Otherwise, the JIT compiler still needs to run.<br />

The ngen utility installs the native image in the native image cache. The physical directory of the native<br />

image cache is < windows > \assem b l y \ N a t i v e I m a g e s .<br />

With ngen install myassembly , you can compile the MSIL code to native code <strong>and</strong> install it into the<br />

native image cache. This should be done from an installation program if you would like to put the assembly<br />

in the native image cache.<br />

With ngen , you can also display all assemblies from the native image cache with the option display . If you<br />

add an assembly name to the display option, you get the information about all installed versions of this<br />

assembly <strong>and</strong> the assemblies that are dependent on the native assembly:<br />

C:\ > ngen display System.AddIn<br />

Microsoft (R) CLR Native Image Generator - Version 4.0.21006.1<br />

Copyright (c) Microsoft Corporation. All rights reserved.<br />

NGEN Roots:<br />

System.AddIn, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=b77a5c561934e089,<br />

processorArchitecture=msil<br />

System.AddIn, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089<br />

NGEN Roots that depend on "System.AddIn":<br />

C:\Program Files (x86)\Common Files\Microsoft Shared\VSTA\Pipeline.v10.0\<br />

AddInSideAdapters\Microsoft.VisualStudio.Tools.Applications.AddInAdapter.v9.0.dll<br />

C:\Program Files (x86)\Common Files\Microsoft Shared\VSTA\Pipeline.v10.0\<br />

AddInSideAdapters\Microsoft.VisualStudio.Tools.Office.AddInAdapter.v9.0.dll<br />

...<br />

If the security of the system changes, it ’ s not sure if the native image has the security requirements it needs<br />

for running the application. This is why the native images become invalid with a system confi guration<br />

change. With the comm<strong>and</strong> ngen update, all native images are rebuilt to include the new confi gurations.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!