I have a Visual Studio 2008 project that I "upgraded" to Visual Studio 2010. Since the upgrade I have been having a lot of problems with the project (a project that was and still is trooper in 2008 I might add).
The first problem is that building the main executable locks the executable, causing further rebuilds to fail. This is described in a related question: http://stackoverflow.com/questions/2002273/visual-studio-locks-output-file-on-build where I picked up the workaround:
if exist "$(TargetPath).locked" del "$(TargetPath).locked"
if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"
Except this workaround works exactly once. The .locked file then is locked by devenv.exe as well and must be moved. I have been working around this by adding .1.locked, .2.locked, etc. The only time that the locks are removed so the files can be deleted is on shutdown of devenv.exe (it takes a few seconds after the UI vanishes, then the files can be removed).
The fact that the debugger does not have to be used to cause this problem points to a pretty serious issue with the 2010 build system.
Some theories I think I can discount:
- Antivirus or other background tasks: if this was a problem it would seem 2008 would fail. However, being a completest I removed the avast! system entirely with no luck.
UPDATE: This project has the same symptoms on a machine with no antivirus and no backup utility. The machines in the office are running XP SP3 32bit, my local machine is Windows 7 64 bit. This appears to be OS independent.
- The debugger is locking the file: all that is required to reproduce this is repeating the build process without debugging. ProcessExplorer shows devenv.exe is the holder of the locks, not the vshost and killing the vshost.exe doesn't remove the locks anyway.
I have a secondary problem that starts to occur once the files get locked: the form designers stop loading with a "can't find assembly" error. I suspect these are related to the earlier locking issue as the designers fire right up prior to a build, but making any changes and rebuilding will cause all the designers to collapse with that error (even ones I have open and as the current view).
It is pitiful to watch a form close to the white error screen just because you changed "dummy=1" to "dummy=2" where "dummy" does absolutely nothing but force a recompile in a completely unrelated assembly.
Update: I have tried a few more remedies: Enable .NET source stepping is not checked, so that isn't the issue. Removing the .SUO (solution user options) simply works for as long as a restart would normally remove the problem (two builds: the first because there is no locked file and the second because there is one, but it can be renamed by the script).
Error 28 Unable to copy file "obj\Debug\PolicyTracker3.exe" to "bin\Debug\PolicyTracker3.exe".
The process cannot access the file 'bin\Debug\PolicyTracker3.exe' because it is being used by another process.