Welcome to MSDN Blogs Sign in | Join | Help

How to Install Assemblies to the GAC Programmatically?

You can add or remove assemblies from the GAC using code. You can use Publish.GacInstall method to install an assembly to the GAC, or Publish.GacRemove method to remove that assembly from the GAC.

If you are using Vista, and enable UAC, you have to run this code using elevated command (run as Administrator), otherwise it won't work.

The other thing that I discovered, this code won't install assembly that is not signed, unfortunately, I did not see any error message/exception. So check if the assembly is a strong-name assembly before installing it.

To check if an assembly is signed:

System.Reflection.Assembly.LoadFile("My.Cool.Assembly.dll").GetName().GetPublicKey().Length > 0;

To install an assembly into the GAC:

new System.EnterpriseServices.Internal.Publish().GacInstall("My.Cool.Assembly.dll");

To uninstall an assembly from the GAC:

new System.EnterpriseServices.Internal.Publish().GacRemove("My.Cool.Assembly.dll");
Published Monday, September 22, 2008 4:06 PM by HelloWorld

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker