add

November 21, 2010

You may receive the “Cannot copy assembly” error message
when you try to build a Visual C# .NET project
cannot copy assembly to file .Access is denied
I remember when the A team used to work for Microsoft instead of Google and Apple.
Unbelievably this bug has been around since at least VS2003. Developers developers developers. ROFL
The good news is that you can rename the file. Create a new application called VS2010_FILELOCK_FIX with the following code:
                    using System;
                    using System.IO;

                    namespace VS2010_FILELOCK_FIX
                    {
                     class Program
                    {
                        static void Main(string[] args)
                        {

                            string path= args[0];
       
                            string random = DateTime.Now.Year + "." + DateTime.Now.DayOfYear + "." + DateTime.Now.Hour + "." + DateTime.Now.Minute + "." + DateTime.Now.Second;

                            try
                            {
                                File.Delete(path);

                            }
                            catch
                            {
                                File.Move(path, path + random);
                            }

                        }
                        }
                    }
          
                    


Next put the path to this exe and the path to your problematic project exe in the pre-build event of your problematic project: "[DirectoryPathVS2010_FILELOCK_FIX]\VS2010_FILELOCK_FIX.exe" "[DirectoryPathToDebugExe]\bin\x86\Debug\[ExeName]"

e.g., "C:\Documents and Settings\UserName\My Documents\visual studio 2010\Projects\VS2010-FILELOCK-FIX\bin\Debug\VS2010-FILELOCK-FIX.exe" "C:\Documents and Settings\UserName\My Documents\Visual Studio 2005\Projects\Development\DOTNET\PSLogParser\PSLogParser\bin\x86\Debug\AppName.exe"