MSBuild 无法删除 Binaries 目录
我正在使用 MSBuild 构建两个解决方案:
<ItemGroup>
<SolutionToBuild Include="$(BuildProjectFolderPath)/HostASPX/SolutionA.sln"/>
<SolutionToBuild Include="$(BuildProjectFolderPath)/../Installer/SolutionB.sln"/>
</ItemGroup>
此构建似乎失败并显示错误消息:
无法删除目录“c:\TeamBuild\Team Solutions\Solution\Binaries”。该目录不为空。
看来 MSBuild 默认情况下会创建此“二进制文件”目录并且构建会通过。当我再次构建时,构建失败并显示上述消息。如果我尝试第三次构建..它会再次工作。
有人可以告诉我如何确保他的文件夹每次都被删除/覆盖吗?
I am building two solutions with MSBuild:
<ItemGroup>
<SolutionToBuild Include="$(BuildProjectFolderPath)/HostASPX/SolutionA.sln"/>
<SolutionToBuild Include="$(BuildProjectFolderPath)/../Installer/SolutionB.sln"/>
</ItemGroup>
It seems that this build fails with the error message:
Unable to remove directory "c:\TeamBuild\Team Solutions\Solution\Binaries". The directory is not empty.
It appears that MSBuild creates this 'Binaries' directory by default and the build passes. When I build again the build fails with the above message. If I try a 3rd build.. it works again.
Can someone tell me how to ensure that his folder is deleted/overwritten each time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定没有观察者效应在起作用吗?即,某些东西没有锁定目录,例如 explorer.exe :P
您可以使用
\\live.sysinternals.com\procmon.exe
来排除它(以找出谁正在对目录执行什么操作) dir) 和 procexp (找出谁锁定了它)。You sure there isn't an observer effect at play? i.e., something isn't locking the directory like explorer.exe :P
You can rule it out by using
\\live.sysinternals.com\procmon.exe
(to find out who is doing what to the dir) and procexp (to find out who is locking it).在运行看起来像这样的目标时,我遇到了同样的问题“无法删除目录...目录不为空”:
偶尔它工作正常并删除了目录,但我经常遇到上面的错误。
最终我发现 MSBuild 本身正在锁定文件,因为它们出现在目标的“输入”上,并且没有及时解锁以供 RemoveDir 删除它们。
将上面的内容更改为:
似乎可以解决问题。
始终删除所有目录仍然可以,因为RemoveDir会跳过不存在的目录并且不会报告错误。
I experienced the same problem of "Unable to remove directory ... the directory is not empty" while running a target that looks something like this:
Occasionally it worked fine and deleted the directories, but often I got the error above.
Eventually I found out that MSBuild itself is locking the files, beacuase they appear on the target's "Inputs", and not unlocking them in time for RemoveDir to delete them.
Changing the above to:
seems to solve the problem.
It's still OK to delete all directories always since RemoveDir skips non-existent directories and does not report an error.