c# - 如何获取真正运行的进程名?

标签 c# process .net-core .net-standard

在 .NET 核心控制台应用程序中,我想获取正在运行的进程名称,我使用了 ProcessName正如文档所说,但它总是返回 dotnet 作为进程名称,而不是正在运行的实际下划线 dll。尽管它是一个 dll,但这是一个控制台应用程序,而不是一个库。

Console.WriteLine(Process.GetCurrentProcess().ProcessName);

输出

dotnet

最佳答案

编辑:

对于 .net 核心,您可以使用:

 System.Reflection.Assembly.GetEntryAssembly().FullName

 System.Reflection.Assembly.GetEntryAssembly().GetName().Name

对于.NET

对于Assmebly Name 'This is my name'的项目

enter image description here

Console.WriteLine(System.Diagnostics.Process.GetCurrentProcess().ProcessName);

打印 This is my name 如下所示。

enter image description here

任务管理器显示

 [assembly: AssemblyTitle("This is my name Title")]

enter image description here

关于c# - 如何获取真正运行的进程名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45227716/

相关文章:

c# - 如何从 Process.Start 中抛出 FileNotFoundException

c# - C# 和 Delphi 之间的管道,如何让它工作?

visual-studio-2015 - xUnit.net v2 未在 Visual Studio 2015 中发现 .NET Core 测试

c# - Excel-C# : How to read the formulas from a cell?

windows - 使用 TerminateProcess 时到底有什么风险?

c# - 我可以仅将 .NET Core 与 F# 一起使用吗?还是我还需要学习 C#?

c# - 以编程方式删除 Azure 应用程序注册 API 权限

C# - 如何显示有关从另一个表检索的 SQL 表的元数据?

c# - 使用 Newtonsoft.Json 检测 json 对象的结尾

c# - WPF:如何绘制这个多边形?