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?