Locking files when building in Visual Studio 2010

前端 未结 11 1909
粉色の甜心
粉色の甜心 2021-02-19 02:28

Hello there, Stackoverflow.

Recently, when I\'ve been programming in Visual Studio 2010, I\'ve been getting the problem with VS locking the bin/Debug/(Pr

相关标签:
11条回答
  • 2021-02-19 03:29

    I've run into this problem a few times myself.

    Mine might not be from the same cause as yours, but I'll tell you what went wrong with me and how I fixed it, hopefully it'll be helpful to you.

    Basically, my program never fully exited properly, even when it appeared to. It would continue to run, and thus continue to lock down the file.

    A quick dirty fix I used initially (and a way to prove if this is the case) is:

    • Open Task Manager (Ctrl-Alt-Del)
    • Click Processes tab
    • Look for your program's name (TileEngine.exe)
    • Note: There will probably be name_vshost.exe (TileEngine_vshost.exe) That's a VisualStudio thing, ignore that, it's not relevant.
    • If you find it, it means your program hasn't actual exited fully.
    • If it's there, click on it and press "End Process"

    So if it's there, then for some reason, your program didn't shut down, like mine did.

    Often, this is from a thread being launched and forgotten, or an Async task that never completes, or something like that.

    Make sure in your OnExiting(..) void function that you kill all running threads.

    If your program is still running despite best attempts to close all threads and other blockers, you can use the very dirty bad method: In OnExiting(...) run the code "System.Diagnostics.Process.GetCurrentProcess().Kill();" - this will taskmanager-style forceshutdown the current process... this is only as an emergency I-can't-make-it-work-any-other-way method.

    0 讨论(0)
  • 2021-02-19 03:30

    I think I found the solution myself. In the Project Properties, "Enable the Visual Studio hosting process" wasn't checked. Checking it seems to have fixed the problems, at least for now.

    Got reminded of it from mcmonkey4eva's post. So thanks for that =)

    And thanks for the other replied I've got. Stackoverflow is awesome!

    0 讨论(0)
  • 2021-02-19 03:30

    I ran into this problem and in my case was due to having bin included in the solution; as soon as I excluded the bin folder from my solution the problem went away.

    0 讨论(0)
  • 2021-02-19 03:31

    I regularly get this problem if I switch from Debug to Release and then immediately F5 to compile. Crazy as it sounds, waiting for, say, one minute after switching between modes will prevent this.

    If it's locked, the only solution is to close Visual Studio and re-open.

    0 讨论(0)
  • 2021-02-19 03:33

    You need to disable Windows Indexer as it locks up the file

    Follow this Guide how to disable

    0 讨论(0)
提交回复
热议问题