23.09.2019
Posted by 

I have a simple WinForms solution in VS 2010. Whenever I build it, output file (bindebugapp.exe) ends up locked, and subsequent builds fail with a message like'The process cannot access the file 'binDebugapp.exe' because it is being used by another process.' The only way to build the project is to restart VS after every build, which is very awkward.I have found this old blog post - it seems that the problem is really old. Does anyone know what is happening here, or at least some workaround?UpdateI don't actually run the file. Locking happens after build, not after debug (i.e. Start VS - build - build - fail!)And I tried turning antivirus off.

It doesn't help.Update 2Process Explorer shows devenv.exe having loaded the file (in DLLs, not in Handles). It seems like some glitch during build prevented the unloading, but the (first) build completes without any messages other then '1 succeeded, o failed'/. Had the same issue, but found a solution (thanks to ):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'. It is not a virus issue.

I've been testing files in Teams. It appears it's keeping files locked open after they're closed in Teams. For example - edit a file in the Teams window, close it, then go try to delete the file 5 minutes later on the SP side, it says it's locked for editing. Right click on the locked file or folder, and select TortoiseSVN-Get lock., and check on ' Steal the locks' at the bottom left corner of the dialog, click 'OK'. If it complete successfully, that's ok. When you right click on the file again, you can see TortoiseSVN-Release lock., click to unlock.

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.' /qif exist '$(TargetPath)' move '$(TargetPath)' '$(TargetPath).locked.%random%'exit /B 0In 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. 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. I had this problem and resolved it with some custom code.

File

See here:Compile the utility in the accepted answer and reference it during the build step as described to workaround the problem. I still turn off VS 2010 at lunch to clean up the morning's work.The reason for the custom code was that the often recommended solution only worked once and then the renamed files were also locked, preventing the rename. Here we just append the data-time info to the file so the renamed versions can't conflict.

View Locked Files

Windows won’t allow you to modify files that open programs have locked. If you try to delete a file and see a message that it’s open in another program, you’ll have to unlock the file (or close the program).In some cases, it may not be clear which program has locked a file. Sometimes, a program or background process may have finished with a file, but not unlocked it properly when it was done. In that case, you must unlock the stubborn file or folder in order to modify the file.Note: Unlocking certain files and deleting them can cause problems with open programs.

The File Is Locked Excel

Don’t unlock and delete files that should remain locked, including Windows system files. Unlock a File with Process ExplorerYou can unlock a file by using the excellent task manager. We’ve before, so here we’ll just dive right into how to unlock a file.

Locked

You won’t need to install it first—it’s a —but you will need to run it with administrative privileges. IObit Unlockeris a useful utility for unlocking files, and it’s free. It even puts a command for unlocking files right on the context menu. After you install the program, you can right-click a stubborn file or folder and select “IObit Unlocker” to open the app with that file selected.You’ll see a list of processes that have locked the file or folder. You can quickly unlock the file by clicking the “Unlock” button. This method unlocks the file while leaving the process running. Note that this may cause problems if a process expects exclusive access to a file.You can also click the “Forced Mode” checkbox and then click “Unlock” to forcibly close whatever program is locking access to the file. You’ll lose any unsaved data in any program killed this way.Once the file is unlocked, you can delete, move, or rename it normally. Fallout 4 combat mods.

In fact, the IOBit Unlocker application has easy “Unlock & Delete”, “Unlock & Rename”, and “Unlock & Move” options. Just click the arrow to the right of the “Unlock” button. Restart Your ComputerGenerally, a file won’t be locked after you restart your computer—unless the program that locked it is a startup program that locks the file as soon as you log in. If you have a stubborn file or folder and don’t want to use any of the tricks here, you can try restarting your computer. You should be able to delete, move, or rename the file as soon as Windows comes back up.RELATED:If the file is being locked by a startup program, you can boot to safe mode to delete it instead. If you’re on Windows 7, press the F8 key during the startup process and select Safe Mode to boot into safe mode. If you’re using Windows 8 or 10, you’ll have to.

Delete (or move) the file in safe mode and restart your computer.There are a variety of other ways to delete locked files. For example, you could use a program to schedule a file deletion when you next restart your computer—the file will be automatically deleted when you reboot. But we’ve found it much easier using one of the methods we’ve detailed here.