C# 如何设置项目的可执行进程名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1055987/
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
How to set a project's executable processname?
提问by Jorge Branco
I'd like to have my executable's process be called ABC. How I can do this? I tried defining my project name as ABC, but then I'll have an ABC.vshost.
我想将我的可执行文件的进程称为 ABC。我怎么能做到这一点?我尝试将我的项目名称定义为 ABC,但随后我将拥有一个 ABC.vshost。
回答by Noldorin
The best you can do is to set the assemblyname in the property pages (Propertiesnode in Solution Explorer) to whatever you wish. The C# compiler automatically uses the assembly name as the process name (file name of the generated EXE), so this should do the job for you. Note that the assembly nameis completely independent from the project name and the root namespace.
您能做的最好的事情是将属性页(解决方案资源管理器中的属性节点)中的程序集名称设置为您想要的任何名称。C# 编译器自动使用程序集名称作为进程名称(生成的 EXE 的文件名),因此这应该为您完成这项工作。请注意,程序集名称完全独立于项目名称和根命名空间。
You can of course change the file name of the EXE after it has been generated (and this will leave the assembly name unchanged), though I see no real reason for this.
您当然可以在生成 EXE 后更改它的文件名(这将使程序集名称保持不变),尽管我认为没有真正的原因。
Note: I assume you are referring to Visual Studio in particular, though it probably matters little in terms of what is possible.
注意:我假设您特别指的是 Visual Studio,尽管就可能的情况而言,它可能无关紧要。
回答by adrianbanks
You can set this in the project's properties page. Setting the assembly name on the application tab will set the name of the resulting compiled assembly (ie. ABC.exe).
您可以在项目的属性页面中进行设置。在应用程序选项卡上设置程序集名称将设置生成的编译程序集的名称(即 ABC.exe)。
The .vshost.exe is the Visual Studio debugging process, used by Visual Studio when you debug. You can turn that off (Visual Studio does not need it to debug) by unchecking the "enable the visual studio hosting process" checkbox on the debug tab of the the project properties.
.vshost.exe 是Visual Studio 调试进程,在调试时由 Visual Studio 使用。您可以通过取消选中项目属性的调试选项卡上的“启用 Visual Studio 托管进程”复选框来关闭它(Visual Studio 不需要它来调试)。
回答by ShuggyCoUk
The processes name in task manager is based of the image name, which is the executable (as already pointed out the assembly name setting defines this in VS.Net).
任务管理器中的进程名称基于映像名称,它是可执行文件(正如已经指出的程序集名称设置在 VS.Net 中定义的那样)。
The Application Name is based on the window title, so is only something you can alter with graphical apps (except via dirty hacks to the console which are unlikely to be stable).
应用程序名称基于窗口标题,因此只有您可以使用图形应用程序更改的内容(除非通过不太可能稳定的控制台脏黑客)。
Note that you can have multiple executables all executing a common main method in a shared dll so you can 'name' different instances of essentially the same code differently if that helps.
请注意,您可以让多个可执行文件都在共享 dll 中执行一个通用的 main 方法,因此如果有帮助,您可以以不同的方式“命名”本质上相同的代码的不同实例。
回答by MunchyG
It seems it's taken from the version-info resource for an .EXE; specifically, the "FileDescription" attribute. To do this programmatically, I imagine you would need a separate program to update the version-info resource in the .EXE whose description you're trying to change. (I don' know C#, but in C++, UpdateResource is used for this purpose.)
它似乎取自 .EXE 的版本信息资源;特别是“FileDescription”属性。要以编程方式执行此操作,我想您需要一个单独的程序来更新您要更改其描述的 .EXE 中的版本信息资源。(我不知道 C#,但在 C++ 中,UpdateResource 用于此目的。)
回答by tony montana
Changing "Assembly name" alone did not help me.Changing Assembly title in AssemblyInfo.cs file helped me to change process name.
单独更改“程序集名称”对我没有帮助。在 AssemblyInfo.cs 文件中更改程序集标题帮助我更改进程名称。