简体   繁体   中英

How to restart Explorer as a pre-build event in Visual Studio

I'd like to restart Explorer when building my DLL in Visual Studio. I've tried adding taskkill /f /IM explorer.exe and start explorer as pre-build events in the project configuration. When I then build my project, Explorer will in fact be terminated, but it will not be successfully restarted. The taskbar will remain missing. Only after starting explorer from a command prompt will it return. I've also tried executing a call to those commands in a .bat file, but I get the same problem (although the.bat file works properly when executed on its own, outside Visual Studio). I've also tried putting the relaunch part in a post-build event, but no dice. Is there any trick to getting Explorer to relaunch successfully in a pre-build event? Thanks for any input.

You can restart Explorer by putting the following commands into a Batch file:

@echo off
taskkill /f /im explorer.exe
start explorer.exe
exit

(The /f switch will f orce the termination of Explorer.)

Then, you can execute that Batch file as a pre-build step (Build Events → Pre-Build Event → Command Line).

If this is a necessary part of your build process, I would recommend adding this Batch file to your solution directory, committing it to your version-control system, and using a relative path in your solution properties.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM