Visual Studio locks output file on build

前端 未结 16 1245
一生所求
一生所求 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 07:03

    It is not a virus issue. It is visual studio 2010 bug. It seems the issue is related to using visual studio gui designer.

    The workaround here is to move locked output file into another temporary one in pre-build event. It make sense to generate temporary file name randomly.

    del "$(TargetPath).locked.*" /q 
    if exist "$(TargetPath)"  move "$(TargetPath)" "$(TargetPath).locked.%random%"
    exit /B 0
    

    In case of using constant temporary file names you will just postpone locks:

    That workaround works exactly once

     if exist "$(TargetPath).locked" del "$(TargetPath).locked"
        if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"
    

    I have also found a solution with 2 temporary files that works exactly 2 times.

    0 讨论(0)
  • 2020-12-02 07:05

    Closing visual studio, reopening, and reloading the most recent solution works around the problem for me. (Visual Studio 2013 Ultimate)

    0 讨论(0)
  • 2020-12-02 07:07

    This is the solution I find out

    1. Uncheck the Visual Studio Hosting Process in project settings as shown below

    1. Kill the exe . it will be your applicationname.vshost.exe from taskmanager

    1. Now you can rebuild you application and run.

    Note: You can re enable this option again with no problems.

    0 讨论(0)
  • 2020-12-02 07:08

    The problem occurred to me too.

    My scenario was this : Running windows 7 (But might also happened in Windows XP) and while working on a project with WPF User Control I could build all of the times, Until opening the XAML file of the User Control - From there, I've got one build, and then the files are locked.

    Also, I've noticed that I was running Visual Studio (Devenv.exe) as Administrator, I've started to run Visual Studio without Administrator privileges and the problem was gone!.

    Let me know if it helped you too. Good luck.

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