Get project name of WPF project [duplicate]

冷暖自知 提交于 2019-12-23 09:12:45

问题


I'm writing my first WPF application, and I'm trying to get the name of the project so I can output it. However, using

Assembly.GetEntryAssembly().GetName()

or

Assembly.GetExecutingAssembly().GetName()

gets me the name as well as the version number(i.e., DataPusher, Version=2.0.466.16967).

Is there a way to get ONLY the assembly name? Thanks.


回答1:


string name = Assembly.GetEntryAssembly().GetName().Name;

or

string name = Assembly.GetExecutingAssembly().GetName().Name;

Alternatively, you can get the Assembly object from any known type in the assembly:

Assembly assy = typeof({class name here}).Assembly;

This also allows another option to get the the name only:

string name = typeof({class name here}).Assembly.GetName().Name;



回答2:


Assembly.GetExecutingAssembly().GetName().Name;



回答3:


Application.ResourceAssembly.FullName will prevent you from having to import System.Reflection also.



来源:https://stackoverflow.com/questions/12862416/get-project-name-of-wpf-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!