Visual Studio locks output file on build

前端 未结 16 1243
一生所求
一生所求 2020-12-02 06:28

I have a simple WinForms solution in VS 2010. Whenever I build it, output file (bin\\debug\\app.exe) ends up locked, and subsequent builds fail with a message like \"

相关标签:
16条回答
  • 2020-12-02 06:43

    Had the same issue, but found a solution (thanks to Keyvan Nayyeri):

    But how to solve this? There are various ways based on your project type but one simple solution that I recommend to Visual Studio add-in developers is to add a simple code to their project's build events.

    You can add following lines of code to the pre-build event command line of your project.

    if exist "$(TargetPath).locked" del "$(TargetPath).locked"
    if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"
    
    0 讨论(0)
  • 2020-12-02 06:43

    I had the same problem and I found out, that VS only locks the exe when I opened a Form or UserControl in VS before building. The solution was quite easy, I just had to close any Form/UserControl before I build the solution and it worked.

    0 讨论(0)
  • 2020-12-02 06:43

    There is also a known issue 533411 where the usage of automatically updating build numbers can cause the locking issue. Workaround from bug report

    Temporary workaround would be disable assembly version update after the rebuild. In AssemblyInfo.cs file, remove the wild card from the AssemblyVersion attribute, for example:
    replace this:
    [assembly: AssemblyVersion("1.4.*")]
    [assembly: AssemblyFileVersion("1.4")]
    with this:
    [assembly: AssemblyVersion("1.4.0.0")]
    [assembly: AssemblyFileVersion("1.4.0.0")]

    0 讨论(0)
  • What about virus scanners on your machine? Can you see any processes that are holding handles to your file (use Process Explorer to find out)?

    Maybe there is "app.exe" visible in your process list, i.e the last version you debugged is still running? When you develop applications which have multiple threads, this may happen if you don't join all of them.

    0 讨论(0)
  • 2020-12-02 06:47

    The only thing that worked for me was to quit Visual Studio 2012, delete the BIN and OBJ folders for the project having problems, and to open Visual Studio again.

    Problem solved... Until next time.

    0 讨论(0)
  • 2020-12-02 06:48

    I've seen this on either a greedy virus scanning software, or if app.exe isn't shutting down properly. Make sure the process isn't still running.

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