You are on page 1of 9

Visual Studio 2010 File Lock Issue

R. V. del Cano September 13, 2012

Error Snapshot
The reason to this issue is that the assembly is locked by one of the previous processes VS 2010 is unable to delete the previous assembly and copy the new one so the build process fails.

How to Possibly Solve it?


1. From the keyboard, press CTRL+ALT+DEL 2. Click Start Task Manager 3. Locate SalesInv (or its equivalent) from the Processes tab 4. Click the End Process button. Then confirm. 5. If it persists, see the next slide
Source: http://stackoverflow.com/questions/2625239/unable-to-copy-a-file-from-obj-debug-to-bin-debug

How to Possibly Solve it?


Do the following:
Close all the design views and then try re-running. Close ALL windows and then try re-running. Unload the project and reload it. Delete the 'obj'-folder. Close Visual Studio and reopen the project via the start page. Reboot the PC.

If it persists, see the next slide

How to Possibly Solve it?


1. Right-click the Project 2. Click Properties

How to Possibly Solve it?


3. Click Build Events 4. In the Pre-build event command line, type the following:

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

But how does this code work? It simply copies the locked file to a new location and lets your build process to be followed.

How to Possibly Solve it?


5. If it doesnt work add the following to the Pre-build event command lines:
if exist "$(TargetPath).locked" del "$(TargetPath).locked" if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked if exist "$(ProjectDir)bin\$(TargetFileName).locked" del "$(ProjectDir)bin\$(TargetFileName).locked" if exist "$(ProjectDir)bin\$(TargetFileName)" if not exist "$(ProjectDir)bin\$(TargetFileName).locked" move "$(ProjectDir)bin\$(TargetFileName)" "$(ProjectDir)bin\$(TargetFileName).locked"

How to Avoid it?


From now on do not close the SalesInv through the built-in Close button on the TitleBar, but instead close it through the Exit submenu from the File Maintenance menu strip. And add the following codes in the Exit submenu: System.Diagnostics.Proc ess.GetCurrentProcess() .Kill(); System.Windows.Forms. Application.Exit();
Do not use this

Use this instead, but add these lines first

Source:
Nayyeri K. (2008). File lock issue in Visual Studio when building a project. Retrieved September 13, 2012, from http://keyvan.io/file-lock-issue-in-visualstudio-when-building-a-project

You might also like