安装程序集到GAC编程安装程序、GAC

2023-09-03 11:37:24 作者:只要爺不死,你們都是孫子

我需要使用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?)