如果是一个exe程序,就可以用Application.ProductName获得,但是现在是一个类库,怎样获取调用者的这个ProductName呢?

解决方案 »

  1.   

    一样的:System.Windows.Forms.Application
      

  2.   

    Assembly asm = Assembly.GetExecutingAssembly();
    if (asm != null)
    {
    object[] customAttributes = asm.GetCustomAttributes(typeof(AssemblyProductAttribute), false);
    if ((customAttributes != null) && (customAttributes.Length > 0))
    {
    Console.WriteLine(((AssemblyProductAttribute)customAttributes[0]).Product);
    }
    }
      

  3.   

    多谢hbxtlhx,但是我刚试了一下,需要把 GetExecutingAssembly 改为 GetEntryAssembly,因为我是在类库里面获得EXE的信息。但是这样还是不行,因为我的项目名称是A,产品名称是B,用这种方法获得是A,怎么获得B这个ProductName呢?
      

  4.   

    哦,可以了,把 GetExecutingAssembly 改为 GetEntryAssembly就行了
      

  5.   

    在你的DLL中引用System.Windows.Forms.Dll,
    在适当的地方通过如下的语句就可以得到调用DLL的误用程序的名称了:string appName = System.Windows.Forms.Application.ExecutablePath;
    Console.WriteLine(System.IO.Path.GetFileName(appName));