Visual Studio 构建失败:无法将 exe 文件从 objdebug 复制到 bindebug [英] Visual Studio build fails: unable to copy exe-file from objdebug to bindebug
问题描述
更新: 可以找到重现此错误的示例项目在 Microsoft Connect 上.我还测试并验证了 下面接受的答案 适用于该示例项目.如果此解决方案对您不起作用,则您可能遇到了不同的问题(属于单独的问题).
Update: A sample project reproducing this bug can be found here at Microsoft Connect. I have also tested and verified that the solution given in the accepted answer below works on that sample project. If this solution doesn't work for you, you are probably having a different issue (which belongs in a separate question).
这是之前在 Stack Overflow 和其他地方问过的一个问题,但到目前为止我发现的所有建议都没有帮助我,所以我只需要尝试提出一个新问题.
This is a question asked before, both here on Stack Overflow and other places, but none of the suggestions I've found this far have helped me, so I just have to try asking a new question.
场景:我有一个简单的 Windows 窗体应用程序(C#、.NET 4.0、Visual Studio 2010).它有几个大多数其他表单继承自的基本表单,它使用实体框架(和 POCO 类)进行数据库访问.没什么特别的,没有多线程或任何东西.
Scenario: I have a simple Windows Forms application (C#, .NET 4.0, Visual Studio 2010). It has a couple of base forms that most other forms inherit from, it uses Entity Framework (and POCO classes) for database access. Nothing fancy, no multi-threading or anything.
问题:暂时一切正常.然后,出乎意料的是,当我准备启动应用程序时,Visual Studio 无法构建.我收到警告 "无法删除文件 '...binDebug[ProjectName].exe'.对路径...binDebug[ProjectName].exe"的访问被拒绝." 和错误无法复制文件 'objx86Debug[ProjectName].exe' 到 'binDebug[ProjectName].exe'.该进程无法访问文件binDebug[ProjectName].exe",因为它正被另一个进程使用.(在运行 Rebuild 时我同时收到警告和错误,但只有在运行 Build - 不认为这是相关的吗?)
Problem: All was fine for a while. Then, all out of the blue, Visual Studio failed to build when I was about to launch the application. I got the warning "Unable to delete file '...binDebug[ProjectName].exe'. Access to the path '...binDebug[ProjectName].exe' is denied." and the error "Unable to copy file 'objx86Debug[ProjectName].exe' to 'binDebug[ProjectName].exe'. The process cannot access the file 'binDebug[ProjectName].exe' because it is being used by another process." (I get both the warning and the error when running Rebuild, but only the error when running Build - don't think that is relevant?)
我完全理解警告和错误消息的内容:Visual Studio 显然正在尝试覆盖 exe 文件,同时由于某种原因它锁定了它.但是,这并不能帮助我找到问题的解决方案......我发现唯一有效的方法是关闭 Visual Studio 并重新启动它.构建并启动然后工作,直到我对某些表单进行了更改,然后我又遇到了同样的问题,不得不重新启动......非常令人沮丧!
I understand perfectly fine what the warning and error message says: Visual Studio is obviously trying to overwrite the exe-file while it at the same time has a lock on it for some reason. However, this doesn't help me find a solution to the problem... The only thing I've found working is to shut down Visual Studio and start it again. Building and launching then work, until I make a change in some of the forms, then I have the same problem again and have to restart... Quite frustrating!
正如我上面提到的,这似乎是一个已知问题,因此有很多建议的解决方案.我将在这里列出我已经尝试过的内容,以便人们知道该跳过哪些内容:
As I mentioned above, this seems to be a known problem, so there are lots of suggested solutions. I'll just list what I've already tried here, so people know what to skip:
创建一个干净的新解决方案,只需从旧解决方案中复制文件.
Creating a new clean solution and just copy the files from the old solution.
将以下内容添加到项目的预构建事件中:
Adding the following to the following to the project's pre-build event:
if exist "$(TargetPath).locked" del "$(TargetPath).locked"
if not exist "$(TargetPath).locked" if exist "$(TargetPath)" move "$(TargetPath)" "$(TargetPath).locked"
将以下内容添加到项目属性(.csproj 文件):
Adding the following to the project properties (.csproj file):
<GenerateResourceNeverLockTypeAssemblies>true</GenerateResourceNeverLockTypeAssemblies>
然而,它们都没有为我工作,所以你可能明白为什么我开始有点沮丧.我不知道还能去哪里找,所以我希望有人能给我一些东西!这是VS中的错误,如果是,是否有补丁?或者我做错了什么,我有循环引用或类似的,如果有,我怎么知道?
However, none of them worked for me, so you can probably see why I'm starting to get a bit frustrated. I don't know where else to look, so I hope somebody has something to give me! Is this a bug in VS, and if so is there a patch? Or has I done something wrong, do I have a circular reference or similar, and if so how could I find out?
非常感谢任何建议:)
更新:正如下面的评论中提到的,我还使用 Process Explorer 检查过它实际上是锁定文件的 Visual Studio.
Update: As mentioned in the comment below, I've also checked using Process Explorer that it actually is Visual Studio that is locking the file.
推荐答案
我找到了一个简单的解决方案,只需禁用项目文件夹和子文件夹的 Windows 索引服务
I found one simple solution, just disable the Windows Indexing Services for the project folder and subfolders
这篇关于Visual Studio 构建失败:无法将 exe 文件从 objdebug 复制到 bindebug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!