Search code examples
c#.netexceptiongac

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.


Solution

  • 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?)