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?
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?
taskkill /F /IM MyApp.vshost.exe 2>&1 || exit /B 0
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With