Visual Studio中生成失败:无法从OBJ \调试EXE文件复制到BIN \调试 [英] Visual Studio build fails: unable to copy exe-file from obj\debug to bin\debug

查看:1569
本文介绍了Visual Studio中生成失败:无法从OBJ \调试EXE文件复制到BIN \调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新: 的样例项目重现这个bug,可以发现<一href="https://connect.microsoft.com/VisualStudio/feedback/details/558848/vsip-rebuilding-a-project-with-open-designers-twice-causes-an-error-with-locked-bin-debug-dlls">here在微软连接的。我也测试和验证的<一个,解决方案给href="http://stackoverflow.com/questions/2895898/visual-studio-build-fails-unable-to-copy-exe-file-from-obj-debug-to-bin-debug/2994502#2994502">the下面接受的答案适用于该示例项目。如果这个解决方案并不为你工作,你可能有一个不同的问题(这属于一个单独的问题)。

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).

这是问过,都在这里对堆栈溢出等地的问题,但没有我发现这一步,帮助我,所以我要尝试提出一个新问题。建议

This is a question asked before, both here on Stack Overflow and other places, but none of the suggestions I've found this far has 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中未能建立,当我正要启动应用程序。我得到了警告的无法删除文件......斌\调试\ [项目] .exe文件,访问路径...斌\调试\ [项目] .exe文件'被拒绝。的和错误的无法复制文件'OBJ \ 86 \调试\ [项目] .exe文件到斌\调试\ [项目] .exe文件'。不能访问该文件的进程'本\调试\ [项目] .exe文件',因为它正由另一个进程使用的(我得到警告信息以及运行重建时的错误,但只有错误运行构建时 - 不认为是相关的? )

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 '...bin\Debug\[ProjectName].exe'. Access to the path '...bin\Debug\[ProjectName].exe' is denied." and the error "Unable to copy file 'obj\x86\Debug\[ProjectName].exe' to 'bin\Debug\[ProjectName].exe'. The process cannot access the file 'bin\Debug\[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 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 works, untill 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:

  • 创建一个新的清洁解决方案,只是将文件从旧的解决方案复制。
  • 添加以下以下到项目的pre-build事件:

  • 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:

如果存在$(TARGETPATH​​).locked德尔$(TARGETPATH​​).locked
&NBSP;&NBSP;如果不存在$(TARGETPATH​​).locked如果存在$(TARGETPATH​​)移动$(TARGETPATH​​)$(TARGETPATH​​).locked

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>

<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?

任何建议,具有很强的AP preciated:)

Any suggestions are highly appreciated :)

更新:正如下面的评论,我也查使用Process Explorer的,它实际上的的Visual Studio中被锁定的文件

Update: As mentioned in comment below, I've also checked using Process Explorer that it actually is Visual Studio that is locking the file.

推荐答案

这是要健全愚蠢,但我想所有这些解决方案,在Windows上运行VS2010 7.他们没有工作,除了改名和建筑,这是非常繁琐的,至少可以说。最终,我找到了罪魁祸首,我觉得很难相信。但是我用的是下面的code中的AssemblyInfo.cs ...

This is going to sound stupid, but I tried all these solutions, running VS2010 on Windows 7. None of them worked except the renaming and building, which was VERY tedious to say the least. Eventually, I tracked down the culprit, and I find it hard to believe. But I was using the following code in AssemblyInfo.cs...

[assembly: AssemblyVersion("2.0.*")]

这是常见的pretty的,但由于某些原因,改变了版本2.0.0.0让事情再次合作。我不知道这是否是Windows 7的具体的东西(我只用它为3-4周),或者如果它是随机的,或者是什么,但它固定为我。我猜VS是保持一个把手就可以生成的每个文件,所以它会知道如何递增的事情呢?我真的不知道,还从来没见过这种情况发生。但是,如果有人在那里也被揪自己的头发,给它一个尝试。

This is pretty common, but for some reason, changing the version to 2.0.0.0 made things work again. I don't know if it's a Windows 7 specific thing (I've only been using it for 3-4 weeks), or if it's random, or what, but it fixed it for me. I'm guessing that VS was keeping a handle on each file it generated, so it would know how to increment things? I'm really not sure and have never seen this happen before. But if someone else out there is also pulling their hair out, give it a try.

这篇关于Visual Studio中生成失败:无法从OBJ \调试EXE文件复制到BIN \调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆