Get executing assembly name from referenced DLL in C#

前端 未结 8 876
野性不改
野性不改 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.

提交回复
热议问题