Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solve "The command "taskkill /F /IM MyApp.vshost.exe" exited with code 128" error [duplicate]

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?

like image 794
Otiel Avatar asked Sep 30 '11 07:09

Otiel


2 Answers

taskkill /F /IM MyApp.vshost.exe 2>&1 || exit /B 0
like image 162
Otiel Avatar answered Oct 05 '22 17:10

Otiel


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.

like image 38
Kev Avatar answered Oct 05 '22 16:10

Kev