解决“命令“taskkill /F /IM MyApp.vshost.exe”问题退出并显示代码 128”错误
上下文
调试(使用“调试”菜单 F5)Visual Studio 解决方案时,会创建一个名为 MyApp.vshost.exe
的进程。当您不恰当地停止调试时 - 我的意思是使用停止调试菜单SHIFT+F5而不是等待出现像 Application.Exit()
这样的代码行 - 该进程不会被终止。
有时,当您稍后再次开始调试应用程序时,会出现一条错误消息,指出该文件(显然,它是调试使用的文件:bin\Debug\MyApp.vshost.exe
)是已经在使用中。
这就是为什么我向构建事件添加了以下命令行: taskkill /F /IM MyApp.vshost.exe
问题
当 MyApp.vshost.exe 进程不存在时,Visual Studio 有时会在构建时抛出错误,从而阻止构建应用程序:
Error c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets
The command "taskkill /F /IM MyApp.vshost.exe" exited with code 128.
我发现的唯一现有解决方案是删除构建事件。
问题
有没有办法在不删除构建事件的情况下解决错误消息?
编辑
我认为最好的解决方案是检索命令的返回代码(errorlevel
),然后如果等于128则返回0。是否可以在Build事件中执行此操作项目?
Context
When debugging (with the Debug menu F5) a Visual Studio solution, a process called MyApp.vshost.exe
is created. When you stop the debug indecently - I mean using the Stop Debug menu SHIFT+F5 and not waiting for a code line like Application.Exit()
occurs - this process is not killed.
Sometimes, when you later start again debugging your application, an error message occurs, saying that the file (obviously, it is the file used by the debug: bin\Debug\MyApp.vshost.exe
) is already in use.
That is why I added to the Build events this command line: taskkill /F /IM MyApp.vshost.exe
Problem
When the MyApp.vshost.exe
process does not exist, Visual Studio is sometimes throwing an error at build time, thus preventing to build the application:
Error c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets
The command "taskkill /F /IM MyApp.vshost.exe" exited with code 128.
The only existing solution i found is to remove the build event.
Question
Is there a way to resolve the error message without removing the build event?
EDIT
I'm thinking the best solution would be to retrieve the return code (errorlevel
) of the command, then return 0 if it is equal to 128. Is it possible to do it in the Build events of the project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
作为临时措施,您可以禁用 Visual Studio 主机进程:
这样做的副作用可能是理想的,也可能是不理想的:
As a temporary measure you can disable the Visual Studio host process:
The side effects of doing this may or may not be desirable:
MyApp.vshost.exe
是 Visual Studio 托管过程。此过程的目的是改善调试体验。如果您自己终止此进程,Visual Studio 将重新创建它。如果您想摆脱它,您可以在项目的调试属性中关闭托管进程(此处显示的 C#):您将遇到的错误描述为“该进程已在使用中”。我不认为我自己经历过这种情况,但在工作电脑上,我在调试后构建时遇到了很大的麻烦。似乎 MyApp.exe 已被锁定且无法覆盖(“文件已在使用中”,而不是“进程”),导致构建失败。据认为,这些问题是由病毒扫描程序(Microsoft Forefront)引起的,但在企业环境中,我无法关闭扫描程序来检验我的假设。
在许多情况下,禁用托管进程不会对您的调试体验产生明显影响。
The
MyApp.vshost.exe
is the Visual Studio hosting process. The purpose of this process is to improve the debugging experience. If you kill this process yourself Visual Studio will recreate it. If you want to get rid of it you can turn off the hosting process in the debugging properties for the project (C# shown here):You describe the error you experience as "the process is already in use". I don't think I have experienced that myself but on a work PC I'm having great troubles when building after debugging. It seems that
MyApp.exe
is locked and cannot be overwritten ("file is already in use", not "process") causing the build to fail. By belief is that a virus scanner (Microsoft Forefront) are causing these problems, but being in a corporate environment I can't turn off the scanner to test my hypothesis.In many cases disabling the hosting process will not have a noticable effect on your debugging experience.
也许以具有完全权限的管理员身份运行 IDE? (我知道这是微软曾经建议过的)
running perhaps as administrator with full privileges the IDE ? ( I know this was suggested once upon a time from Microsoft )