Search code examples
c#installationuninstallationgac

install or uninstall DLLs from Assembly


I tried to find a way for intalling and uninstalling dlls from the GAC by C# code, but the only thing I find about it that's something with "Gacutil.exe", and it's very unclear how to use it.

There is a better way for install\ uninstall files from the GAC. Thanks


Solution

  • You can use PowerShell, for example. Or as you say use gacutill but Micsrosoft say:

    Gacutil.exe is only for development purposes and should not be used to install production assemblies into the global assembly cache.

    In my opinion best way is use installer to do this job. Libraries into the GAC should be added only during the installation and removed only during deinstallation.

    Here is example how to setup installer. I think others installer should do this, too.

    After research i found this: (as you want c# code ;-) )

    To install an assembly into the GAC:

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

    To uninstall an assembly from the GAC:

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