Unable to copy file reference.dll to bin/reference.dll. The process cannot access the file reference.dll because it is being used by another process

后端 未结 30 2210
深忆病人
深忆病人 2021-01-31 03:34

For one of my ASP.NET 3.5 applications, every single time I try to build the web app, it throws the following build errors in Visual Studio 2008:

Error 16

30条回答
  •  悲哀的现实
    2021-01-31 03:49

    What worked for me is the following pre-build event:

    if exist "$(TargetPath).locked.bak" del "$(TargetPath).locked.bak"
    if exist "$(TargetPath).bak" del "$(TargetPath).bak"
    if exist "$(TargetPath).locked" ren "$(TargetPath).locked" "$(TargetFileName).locked.bak"
    if exist "$(TargetPath)" ren "$(TargetPath)" "$(TargetFileName).bak"
    

    What I have noticed in my case is that the 2 files are being created and can not be deleted. You can, however, rename them (and they are still in use if you try to delete them). On a next build, the renamed files are no longer in use (lock removed) and they can be deleted, which is what the above script does, after which it can safely rename the new locked files so there will be no problems in generating the build output.

    The other pre-build events posted here and in other places did not help me a lot (they worked only for one extra build or only a few before the problem arose again). So now I am currently using the one posted above for my debugging purposes.

提交回复
热议问题