From Time to time my visual studio 2010 occupies the executable program in Debug subdirectory.
Thus I have to unload the solution and reload it. Then ReBuild it and then run it.
The all situatuation becomes upseen
I really can't work like that.
I have already unclick in Debug section the
Enable the Virtual Studio hosting process
Is there any one to help me on this situation?

- 1,229
- 6
- 26
- 63
-
1What do you mean by occupies? Is there some specific error message you get? – mjcopple Mar 28 '11 at 21:45
-
@mjcopple. When I say "occupies" I mean it holds it and I can't deleted. This phenomenon it's not happens every time. Suddenly comes up and suddenly disappears. – Lefteris Gkinis Apr 11 '11 at 06:35
-
Are you running your built app with CTRL-F5? This spawns an independent process that will cause consequent builds to fail since the executable is held and cannot be overwritten. – lysergic-acid Apr 23 '11 at 08:44
-
I suggest you check out external packages or VS addins that could run in your VS instance and see if it continues to work. You could also ensure your antivirus is not messing with your build directories, some of these programs are picky about this. – Simon Mourier Apr 24 '11 at 07:04
-
I always use CTRL+SHIFT+B to build my programs in between development cycles. If you could explain what you're doing to build or to debug your solution we could give you better help. Also, remember that if you're running in debug mode you can't change parts of your code that are meant to be compiled! That includes the outcome, that is your executable! – bastianwegge Apr 26 '11 at 13:35
-
@Liortal. I'm running the code with debug mode by pressing the green key "RUN" – Lefteris Gkinis Apr 27 '11 at 08:47
-
@Simon Mourier. I don't have any external add in – Lefteris Gkinis Apr 27 '11 at 08:48
-
@Wegginho. Whose says that I'm trying to make changes during the debug mode? I'm just run my code with debug mode open. and some times founds the final exe locked and some times is unlocked without making any change from me. This time of period is working fine. – Lefteris Gkinis Apr 27 '11 at 08:51
-
Do you see your application's process running in task manager when the file is locked? – lysergic-acid Apr 27 '11 at 10:15
-
Can you attach to it using WinDBG and see what is it doing exactly ? you may find that it is leaving some Threads running or something like that that does not completely shut down the process. – lysergic-acid Apr 28 '11 at 10:59
-
@liortal. Leaving Threads is not a slow process and in any case after passing 5min or 30min the exe file needs to be released. Here is not released – Lefteris Gkinis Apr 28 '11 at 16:30
3 Answers
Well this is a bit of a workaround but works for me most of the time. This doesn't solve the root cause but the symptoms (the file locking):
Add this as a pre-build event:
if exist "$(TargetPath).locked" del "$(TargetPath).locked"
if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"
(Source of the solution: http://nayyeri.net/file-lock-issue-in-visual-studio-when-building-a-project)
Also here there is a similar problem and a liberal solution: Visual Studio 2010 build file lock issues

- 1
- 1

- 25,584
- 6
- 69
- 80
-
@Teoman Soygul. I read your solution and it is like you said it doesn't solve the root of the problem. I have in mind to appeal to microsoft thou a serious channel, which i don't know what will be. – Lefteris Gkinis Apr 27 '11 at 09:11
-
3Here you can fill in a bug report, they take it seriously: http://connect.microsoft.com/VisualStudio – Teoman Soygul Apr 27 '11 at 10:07
-
@Teoman Soygul. I found that your approach to the issue is the most close to what I'm looking for. And just for this I decide to give you the 50points of reputation credit. Thank you very much for your concern. – Lefteris Gkinis Apr 28 '11 at 06:55
-
You're welcome. This works form me most of the time for this sort of lockups. – Teoman Soygul Apr 28 '11 at 11:10
-
@Teoman Soygul. I vote your answer because you know it from the first time that the answer is a solution which will not come from our own moves, thats why you said "It's not solving the root of the problem" but needs to face it as a bug from MS. And secondly you proposed me a serious place to post it as a bug – Lefteris Gkinis Apr 28 '11 at 16:26
It may also not be Visual Studio locking your executable, check the locks on it with "Unlocker": http://www.emptyloop.com/unlocker/

- 1,231
- 5
- 16
- 36
-
I did that and the lock is coming from the VS itself. The lock is coming suddenly and goes itself, just like that. – Lefteris Gkinis Apr 27 '11 at 08:53
When this happens I open Process Explorer and use the Find - Find Handle or Dll menu to find the process which has the file still open. From there I can jump the the handle in the process and close it from within Process Explorer. That works although it is a bit hacky.
Yours, Alois Kraus

- 13,229
- 1
- 38
- 64
-
Klaus. Yes I do that as well, but this is not the solution in the problem. – Lefteris Gkinis Apr 28 '11 at 06:30