Error 2 Unable to copy file "obj\Debug\xxx.dll" to "bin\xxx.dll". The process cannot access the file 'bin\xxx.dll' because it is being used by another process.
解决方案:
方法一:
在预生成事件命令行加入如下代码:
IF EXIST $(TargetPath).LOCKED (del $(TargetPath).LOCKED) ELSE (IF EXIST $(TargetPath) (move $(TargetPath) $(TargetPath).LOCKED))
方法二:
在预生成事件命令行加入如下代码:
if exist "$(TargetPath).locked" del "$(TargetPath).locked"
if not exist "$(TargetPath).locked" if exist "$(TargetPath)" move "$(TargetPath)" "$(TargetPath).locked"
然后把这个命令添加到“工程属性”——〉“生成事件”——〉“预生成事件”——〉“命令行”的编辑框内。
-------------------------------------------------------------------------------------------------------
Visual Basic 中的生成事件可以用来运行脚本、宏或作为编译过程一部分的其他操作。预生成事件在编译之前发生;生成后事件在编译之后发生。
生成事件是在“生成事件”对话框中指定的,该对话框可以从“项目设计器”的“编译”页进行访问。
如何指定预先生成和后期生成事件
指定生成事件
-
在“解决方案资源管理器”中选定一个项目,然后在“项目”菜单中单击“属性”。
-
单击“编译”选项卡。
-
单击“生成事件”按钮以打开“生成事件”对话框。
-
输入预生成或生成后操作的命令行参数,然后单击“确定”。
注意
在运行 .bat 文件的所有后期生成命令之前添加一个 call 语句。例如,call C:\MyFile.bat 或 call C:\MyFile.bat call C:\MyFile2.bat。
http://social.msdn.microsoft.com/Forums/zh-CN/csharpide/thread/68648642-08d8-4cff-b0c3-c2782f010589
http://hi.baidu.com/star_161510/blog/item/c8b9a3d5fa00d6ce51da4ba2.html
http://stackoverflow.com/questions/1121386/unable-to-copy-file-reference-dll-to-bin-reference-dll-the-process-cannot-access