c# - 无法将文件从 obj\Debug 复制到 bin\Debug

标签 c# winforms visual-studio

我有一个 C# 项目,每次我尝试编译该项目时都会收到此错误:

(Unable to copy file "obj\Debug\Project1.exe" to "bin\Debug\Project1.exe". The process cannot access the file 'bin\Debug\Project1.exe' because it is being used by another process.)

所以我必须从任务管理器中关闭进程。我的项目只有一种形式,没有多线程。

解决方案是什么(不重启 VS 或终止进程)?

enter image description here

最佳答案

这应该有效。

转到您的项目属性。 在 Build Events 中,在 Pre-build event command line 下,添加这两行代码:

if exist "$(TargetPath).locked" del "$(TargetPath).locked"
if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"

关于c# - 无法将文件从 obj\Debug 复制到 bin\Debug,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2625239/

相关文章:

c# - Process.GetCurrentProcess().MainWindowHandle 返回零

c# - 同时选择不同 TreeView 中的2个节点

c# - 阻止 Visual Studio 2013 自动删除分配中的额外空格

c# - 如何使我的表单透明,但我在上面绘制的内容却不透明?

c - 通过引用传递,不同基类型的错误

c++ - VC++ Glew 外部链接错误

c# - 无论如何,sitecore 中是否自动接受克隆通知?

c# - 两个远程 sql 连接时 Transactionscope 不工作

c# - 子线程如何将其状态/进度通知父线程?

c# - volatile 字典中的对象继承 volatile 行为吗?