Get executing assembly name from referenced DLL in C#

前端 未结 8 851
野性不改
野性不改 2020-12-08 19:20

What is the best way to get the application name (i.e MyApplication.exe) of the executing assembly from a referenced class library in C#?

I need to open the applicat

相关标签:
8条回答
  • 2020-12-08 19:45

    If you want the name of the parent EXE and not the referenced DLL assembly - you will need to use this:

    Assembly.GetEntryAssembly().GetName().Name
    

    This will return the EXE name (minus the .EXE part).

    Using GetExecutingAssembly() is not right as per the OP's question (first paragraph of it!) as it will return the DLL name.

    0 讨论(0)
  • 2020-12-08 19:48

    If you want to read (and display) version number:

      Assembly ass = System.Reflection.Assembly.GetExecutingAssembly();
      AssemblyName assname = ass.GetName();
    
      Version ver=assname.Version;
    

    Somewhere in application (ie Title block in a Windows form)

     this.Text = "Your title    Version " + ver;
    
    0 讨论(0)
提交回复
热议问题