Quantcast
Channel: DIMAKA's BLOG - Setup
Viewing all articles
Browse latest Browse all 7

Installing assembly into the GAC programmatically

$
0
0

Working on new Neutron installer (which is not MSI based due to some troubles related to Vista UAC system) I had to install the assembly into the GAC without using gacutil.exe. I mean programmatically.

I googled some blog posts on this subject. The first article proposed to use Windows Installer. From my point of view it is too complicated. After that I read about programmatic modifying the GAC with the Fusion APIs (C++ example and managed one). Smells like a hack. Rejected as well.

And then I found the awesome post which describes a really good solution of my problem: you can use System.EnterpriseServices.Internal.Publish class to install your assembly into the GAC and uninstal it back!

You just need to write a line of code:

new System.EnterpriseServices.Internal.Publish().GacInstall(”myassembly.dll”);

NOTE: I have re-posted my post from Neutron blog, where I used to posted in the past.

There were a few comments added:

----------- Raghav

thanks Dmitry for your post.

I tried this method. But I didn’t see the assembly in assembly cache. Also there is no error with GacInstall method. Do you have any idea?

----------- Dmitry Pavlov

Hi Raghav,

I have never got the problem you described with GacInstall method. Every time I call this method assembly successfully falls into the GAC.

You can overview the sources of GacInstall method with Reflector for .NET. Open C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.EnterpriseServices.dll file in Reflector and press F3. Then select ‘Search Member’ type and enter ‘GacInstall’. That may help you to figure out the reason of your problem.

Hope that helps!

----------- Olivier

Funny, but while reflectoring System.EnterpriseServices.Internal.Publish.GacInstall, I noticed the functionality relied on fusion.dll … At least, Microsoft is eating its own dog hack. And you can rely on it, for it is documented. ;-)


Viewing all articles
Browse latest Browse all 7

Trending Articles