How do I add a DLL to GAC

6.8k views Asked by At

This is my code:

Register(Assembly.GetExecutingAssembly()).Location);

private void Register(String assemblyName)
{
    System.Diagnostics.ProcessStartInfo processStartInfo = new System.Diagnostics.ProcessStartInfo("D://gacutil.exe", string.Format("/i {0}", assemblyName));
    processStartInfo.UseShellExecute = false;
    System.Diagnostics.Process process= System.Diagnostics.Process.Start(processStartInfo);
    process.WaitForExit();
}

How do I add the DLL to the assembly Folder?

3

There are 3 answers

4
Kurubaran On

MSDN Publish.GacInstall

Use GacInstall() method in the Publish class to GAC the assembly easily. Add reference to System.EnterpriseServices. Please make sure particular dll is Signed. Only signed assembly can be added to GAC.

private void Register(String assemblyName)
  {
      Publish publish = new Publish();
      publish.GacInstall(assemblyName);
  }
0
sara On

You need either to set the working directory of teh process to your current working directory or to send the full path of the .dll

0
Anand On

You have to put the entire assembly path for this to work. For example

gacutil /i D:/someassembly

Rest of your code looks fine. Just use whole assembly path instead of just assembly name.