MSBuild 无法删除 Binaries 目录

发布于 2024-09-13 12:34:52 字数 531 浏览 7 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

隱形的亼 2024-09-20 12:34:52

您确定没有观察者效应在起作用吗?即,某些东西没有锁定目录,例如 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).

千纸鹤 2024-09-20 12:34:52

在运行看起来像这样的目标时,我遇到了同样的问题“无法删除目录...目录不为空”

 <Target Name="CleanFiles"
    DependsOnTargets="Prepare_Files"
    Inputs="@(Files->'%(OutputPath)'->Distinct())"
    Outputs="_Non_Existent_Item_To_Batch_">

    <ItemGroup>
      <DirsToDelete Include="@(Files->'%(OutputPath)'->Distinct())"/>      
    </ItemGroup>

    <RemoveDir Directories="@(DirsToDelete)"/>

  </Target>

偶尔它工作正常并删除了目录,但我经常遇到上面的错误。

最终我发现 MSBuild 本身正在锁定文件,因为它们出现在目标的“输入”上,并且没有及时解锁以供 RemoveDir 删除它们。
将上面的内容更改为:

 <Target Name="CleanFiles"
    DependsOnTargets="Prepare_Files">

    <ItemGroup>
      <DirsToDelete Include="@(Files->'%(OutputPath)'->Distinct())"/>      
    </ItemGroup>

    <RemoveDir Directories="@(DirsToDelete)"/>

  </Target>

似乎可以解决问题。

始终删除所有目录仍然可以,因为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:

 <Target Name="CleanFiles"
    DependsOnTargets="Prepare_Files"
    Inputs="@(Files->'%(OutputPath)'->Distinct())"
    Outputs="_Non_Existent_Item_To_Batch_">

    <ItemGroup>
      <DirsToDelete Include="@(Files->'%(OutputPath)'->Distinct())"/>      
    </ItemGroup>

    <RemoveDir Directories="@(DirsToDelete)"/>

  </Target>

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:

 <Target Name="CleanFiles"
    DependsOnTargets="Prepare_Files">

    <ItemGroup>
      <DirsToDelete Include="@(Files->'%(OutputPath)'->Distinct())"/>      
    </ItemGroup>

    <RemoveDir Directories="@(DirsToDelete)"/>

  </Target>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文