安装程序集到GAC编程 [英] Install an assembly into GAC programmatically

查看:232
本文介绍了安装程序集到GAC编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用C#在GAC中安装程序集。下面是我的code:

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

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

以上code给出了错误:

The above code gives the error:

所需的绝对路径

但我需要这不使用静态文件的路径(绝对路径)运行。谁能告诉我它是否可能?我已经加入了参考里面的项目引用的程序集。我需要安装内部GAC该组件。

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.

推荐答案

您可以这样做:

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

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

假设该文件在当前工作目录。如果不是,那么你需要定义什么规则,正在被用来查找此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?)

这篇关于安装程序集到GAC编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆