放入GAC中的组件,如何编程获得组件所在路径(不是GAC中的路径)
蝈蝈俊 2003-08-22 03:47:52 比如有个自己编写的组件a ,这个组件是放到: C:\Temp1\ 目录下,我们把这个组件注册到GAC(全局应用程序缓存)中。
然后有个程序b ,调用这个组件的某个静态方法 method1 ,这个方法返回组件a 放到应用程序缓存之前的目录,也就是上面的 C:\Temp1\ 目录。
(程序 b 不在 C:\Temp1\ 目录下)
问题是我如何在组件a 的 method1 方法中获得上面的目录,也就是 C:\temp1\ 目录
简单代码范例:
组件a 的代码:
using System;
namespace ClassLib
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class Class1
{
public Class1()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static string GetPathString()
{
string strPath = "";
//strPath = AppDomain.CurrentDomain.BaseDirectory.ToString();
//strPath = typeof(Class1).Assembly.Location;
//strPath = typeof(Class1).Assembly.FullName;
//strPath = Environment.CurrentDirectory.ToString();
//strPath = typeof(Class1).Assembly.EscapedCodeBase ;
return strPath;
}
}
}
说明: 以上注释部分获得的路径大多都是
c:\winnt\assembly\gac\classlib\1.0.1329.28212__fe6c2fac35797991\classlib.dll
这样的路径,而不是我需要的: C:\temp1\ 这个路径。
程序 b 调用组件 a
using ClassLib;
private void button1_Click(object sender, System.EventArgs e)
{
textBox1.Text = Class1.GetPathString();
}
程序 b 中引用的是放入GAC 的组件 a