解决“命令“taskkill /F /IM MyApp.vshost.exe”问题退出并显示代码 128”错误

发布于 2024-12-07 05:37:02 字数 886 浏览 3 评论 0原文

上下文
调试(使用“调试”菜单 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.exeprocess 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

黄昏下泛黄的笔记 2024-12-14 05:37:02
taskkill /F /IM MyApp.vshost.exe 2>&1 || exit /B 0
taskkill /F /IM MyApp.vshost.exe 2>&1 || exit /B 0
秋意浓 2024-12-14 05:37:02

作为临时措施,您可以禁用 Visual Studio 主机进程:

如何:禁用托管进程

禁用托管进程

在 Visual Studio 中打开项目。

在“项目”菜单上,单击“属性”。

单击“调试”选项卡。

清除“启用 Visual Studio 托管进程”复选框。

这样做的副作用可能是理想的,也可能是不理想的:

一般来说,当托管进程被禁用时:

开始调试 .NET Framework 应用程序所需的时间
增加。

设计时表达式评估不可用。

部分信任调试不可用。

As a temporary measure you can disable the Visual Studio host process:

How to: Disable the Hosting Process

To disable the hosting process

Open a project in Visual Studio.

On the Project menu, click Properties.

Click the Debug tab.

Clear the Enable the Visual Studio hosting process check box.

The side effects of doing this may or may not be desirable:

In general, when the hosting process is disabled:

The time needed to begin debugging .NET Framework applications
increases.

Design-time expression evaluation is unavailable.

Partial trust debugging is unavailable.

踏雪无痕 2024-12-14 05:37:02

MyApp.vshost.exeVisual 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):

Debug project properties

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.

阳光的暖冬 2024-12-14 05:37:02

也许以具有完全权限的管理员身份运行 IDE? (我知道这是微软曾经建议过的)

running perhaps as administrator with full privileges the IDE ? ( I know this was suggested once upon a time from Microsoft )

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文