放入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
...全文
118 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
fa2002 2003-08-26
  • 打赏
  • 举报
回复
ghj1976 (蝈蝈俊.net) :是个爱钻牛角尖人,他问的问题都有点“变态”的。 :)
lbx1979 2003-08-26
  • 打赏
  • 举报
回复
其实把配置信息放到一个系统路径也是一个方法吧
Azmore 2003-08-26
  • 打赏
  • 举报
回复
i can't find the file of _AssemblyInfo_.ini,why?
sumtec 2003-08-25
  • 打赏
  • 举报
回复
如果是Winform下面的dll,可以在做安装程序的时候写注册表啊。
jabill 2003-08-25
  • 打赏
  • 举报
回复
gz
bpy 2003-08-24
  • 打赏
  • 举报
回复
哇。这个问题值得继续关注,学习。
蝈蝈俊 2003-08-24
  • 打赏
  • 举报
回复
目前就只有一个方法,去读取 __AssemblyInfo__.ini 文件中的信息。

LevinForum 2003-08-23
  • 打赏
  • 举报
回复
他的意思是:

现在有一个Assembly - A
装在
C:\A 里。
附带一些文件,例如a.jpg,a.avi,a.doc,a.xml之类的。

因为某些原因,要把 A 装在 GAC 中。

那么程序引用的是GAC中的A咯。

但是怎样才能得到a.jpg,a.avi...呢?
-----------------------------------------

。。。。

实际上,这是个协议,不是技术上的问题,看你怎样定而已。

例如A是个独立的组件,那么可以在安装的时候把相关文件路径记录到注册表中啊。。

bpy 2003-08-23
  • 打赏
  • 举报
回复
华山论剑——难得
win32c 2003-08-23
  • 打赏
  • 举报
回复
眼花啊
hvq 2003-08-23
  • 打赏
  • 举报
回复
追星
蝈蝈俊 2003-08-23
  • 打赏
  • 举报
回复
to : webdiyer(陕北吴旗娃)

我写的不是Web组件,是没有界面,只有算法、运算的组件,当然不是从 System.Web.Control继承的

蝈蝈俊 2003-08-23
  • 打赏
  • 举报
回复
对,我的意思就是: LevinForum 所说的,因为那个目录下有这个组件的一些配置信息文件。

我要获得这个文件的具体路径。

这个路径又不好写死。只有这样了。

但是却无法获得。郁闷。
saucer 2003-08-23
  • 打赏
  • 举报
回复
I told 蝈蝈, an assembly in GAC is independent, he doesn't believe me, :-(
qqchen79 2003-08-23
  • 打赏
  • 举报
回复
Yes, saucer is right.
Microsoft does keep a copy of the CodeBase information in the __AssemblyInfo__.ini, it's named URL. For example:

C:\WINNT\assembly\GAC\TestServer\1.0.0.0__0cb579616e939126>type __AssemblyInfo__.Ini
[AssemblyInfo]
MVID=ba958a132a5a634f8e58d3f7d0508f95
URL=file:///C:/PROGRA~1/MICROS~2.NET/FRAMEW~1/Samples/QuickStart/howto/samples/interop/testserver_1/vb/TestServer.dll
DisplayName=TestServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0cb579616e939126
qqchen79 2003-08-23
  • 打赏
  • 举报
回复
为什么一定要这个信息呢?
既然.NET已经在GAC里面保存了assembly的一个copy,那么原来的路径和文件信息就是多余的。事实上在安装之后你甚至可以安全的删掉原始文件。
saucer 2003-08-23
  • 打赏
  • 举报
回复
this answer from Microsoft is interesting, but I couldn't find the information from __AssemblyInfo__.ini:


http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=T%24Qixs58CHA.2324%40cpmsftngxa06
saucer 2003-08-23
  • 打赏
  • 举报
回复
this guy is asking the same question and check the answer from other people, it is same answer I told you yesterday


http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=enE4STBBDHA.1220%40TK2MSFTNGP11.phx.gbl&rnum=2&prev=/groups%3Fq%3DGAC%2Bassembly%2Blocation%2Boriginal%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3DenE4STBBDHA.1220%2540TK2MSFTNGP11.phx.gbl%26rnum%3D2
webdiyer 2003-08-22
  • 打赏
  • 举报
回复
它是Control类的一个属性,只要你的类是从System.Web.Control继承的,就可以直接用这个属性。
蝈蝈俊 2003-08-22
  • 打赏
  • 举报
回复
TemplateSourceDirectory ???

如何用?? 我写的是dll组件,不是有界面的那类组件呀。
加载更多回复(1)

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧