如何在不使用 ItemsGroup 的情况下使用 MSBuild Delete 任务删除文件列表

How to delete a list of files with MSBuild Delete task without using ItemsGroup

我知道,可以在 <ItemsGroup> 的帮助下使用 MSBuild Delete 任务删除文件列表。如前所述 here。但是,有没有一种方法可以在不使用 .

基本上可以删除任务做类似<Exec Command="del /f /q *.pdp"/>

的事情

看来你想要的是这样的:

<Target Name="TestDelete" AfterTargets="xxx">
    <Delete Files="$(Outputpath)*.pdb"/>
</Target>

但据我所知,msbuild 任务参数.

无法识别通配符

恐怕答案是否定的。我建议您在 Items 中使用通配符来引用文件列表。

勾选MSBuild Items and MSBuild Tasks。官方文档中只有Items明确表示支持通配符。

此外,您可以查看此 similar issue

更新:

其实并不确定具体设计的真正原因。我刚刚阅读了 Task Writing 文档。并编写一个简单的 MyDelete 任务进行研究。

public class MyDelete:Task
    {
        [Required]
        public string MyProperty { get; set; }

        public override bool Execute()
        {
            // Log a high-importance comment
            Log.LogMessage(MessageImportance.High,
                "MyDelete Task has delete files: \"" + MyProperty + "\".");
            return true;
        }
    }

然后我将下面的脚本添加到项目文件中:

<UsingTask TaskName="MyMessage.MyDelete"
        AssemblyFile="MyDelete.dll"/>

  <Target Name="MyTarget" AfterTargets="build">
    <ItemGroup>
      <MyItem Include="$(Outputpath)*.*"/>
    </ItemGroup>
    <MyDelete MyProperty="$(Outputpath)*.*"/>
    <MyDelete MyProperty="@(MyItem)"/>
  </Target>

构建输出应该是这样的:

我的猜测是对于大多数任务,属性是字符串,所以包含通配符的输入是一个字符串变量“path*.*”,它无法被代码识别任务直接.

但是对于Item,根据文档:Item types are named lists of items that can be used as parameters for tasks.所以输入是像“xxx;xxx;xxx ...”这样的字符串,表现很好。

我的更新只是为了深入研究,很难回答设计的具体原因。我想如果你真的想知道设计原因,你可能需要通过 this link.

向支持该产品的人寻求帮助