![C#通过代码判断并注册程序集到GAC C#通过代码判断并注册程序集到GAC](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
var dllName = "EasyHook.dll";
var dllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dllName);
if (System.Runtime.InteropServices.RuntimeEnvironment.FromGlobalAccessCache(Assembly.LoadFrom(dllPath)))
new System.EnterpriseServices.Internal.Publish().GacRemove(dllPath);
Thread.Sleep();
new System.EnterpriseServices.Internal.Publish().GacInstall(dllPath);
Thread.Sleep();
if (System.Runtime.InteropServices.RuntimeEnvironment.FromGlobalAccessCache(Assembly.LoadFrom(dllPath)))
Console.WriteLine("{0} registered to GAC successfully.", dllName);
else
Console.WriteLine("{0} registered to GAC failed.", dllName); dllName = "ComplexParameterInject.dll";
dllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dllName);
if (System.Runtime.InteropServices.RuntimeEnvironment.FromGlobalAccessCache(Assembly.LoadFrom(dllPath)))
new System.EnterpriseServices.Internal.Publish().GacRemove(dllPath);
Thread.Sleep();
new System.EnterpriseServices.Internal.Publish().GacInstall(dllPath);
Thread.Sleep();
if (System.Runtime.InteropServices.RuntimeEnvironment.FromGlobalAccessCache(Assembly.LoadFrom(dllPath)))
Console.WriteLine("{0} registered to GAC successfully.", dllName);
else
Console.WriteLine("{0} registered to GAC failed.", dllName);