Visual Studio locks output file on build

前端 未结 16 1364
一生所求
一生所求 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.

提交回复
热议问题