获取 WPF 项目的项目名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12862416/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get project name of WPF project
提问by PiousVenom
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
我正在编写我的第一个 WPF 应用程序,我正在尝试获取项目的名称,以便我可以输出它。但是,使用
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).
给我名字和版本号(即 DataPusher,Version=2.0.466.16967)。
Is there a way to get ONLY the assembly name? Thanks.
有没有办法只获得程序集名称?谢谢。
回答by Steve Konves
string name = Assembly.GetEntryAssembly().GetName().Name;
or
或者
string name = Assembly.GetExecutingAssembly().GetName().Name;
Alternatively, you can get the Assemblyobject from any known type in the assembly:
或者,您可以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;
回答by swiftgp
Assembly.GetExecutingAssembly().GetName().Name;
回答by mrmichaeldev
Application.ResourceAssembly.FullName will prevent you from having to import System.Reflection also.
Application.ResourceAssembly.FullName 将防止您也必须导入 System.Reflection。

