Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install an assembly into GAC programmatically

I need to install an assembly in GAC using c#. Below is my code:

new System.EnterpriseServices.Internal.Publish().GacInstall("MyAssembly.dll");

The above code gives the error:

Absolute path required

But i need this to run without using static file path (absolute path). Can anyone tell me whether its possible? I have added the reference to the assembly inside the project references. I need to install this assembly inside GAC.

like image 678
sharmila Avatar asked Sep 12 '12 07:09

sharmila


People also ask

How do I add and remove assembly from GAC?

There are two ways to remove an assembly from the global assembly cache (GAC): By using the Global Assembly Cache tool (Gacutil.exe). You can use this option to uninstall assemblies that you've placed in the GAC during development and testing. By using Windows Installer.


1 Answers

You could do something like:

GacInstall((new System.IO.FileInfo("MyAssembly.dll")).FullName);

or,

GacInstall(System.IO.Path.GetFullPath("MyAssembly.dll"));

Assuming that the file is in your current working directory. If it's not, then you need to define what rules are being used to find this DLL (e.g. is it in the same path as your current executable?)

like image 186
Damien_The_Unbeliever Avatar answered Sep 18 '22 02:09

Damien_The_Unbeliever