如何在不使用ItemsGroup的情况下使用MSBuild Delete任务删除文件列表 [英] How to delete a list of files with MSBuild Delete task without using ItemsGroup

查看:89
本文介绍了如何在不使用ItemsGroup的情况下使用MSBuild Delete任务删除文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,可以在<ItemsGroup>的帮助下使用MSBuild Delete任务删除文件列表.如此处所述.但是,有一种方法可以不使用来执行相同的操作.

I know, a list of files can be deleted using MSBuild Delete task with the help of <ItemsGroup>. As mentioned here. However is there a way to do the same without using the .

基本上可以删除任务,执行与<Exec Command="del /f /q *.pdp"/>

Basically can delete task do something similar to <Exec Command="del /f /q *.pdp"/>

推荐答案

似乎您想要的是这样的东西:

It seems what you want is something like:

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

但是据我所知, msbuild任务参数中无法识别通配符.

But as I know the wildcard is not recognized in msbuild task parameters.

因此,恐怕答案是否定的.我建议您在项目"中使用通配符来引用文件列表.

So the answer is negative I'm afraid. I recommend you use wildcard in Items to refer to the list of files.

检查 MSBuild任务.在官方文档中,只有"Items"明确声明它支持通配符.

Check MSBuild Items and MSBuild Tasks.In official document, only Items is clearly stated that it supports for wildcards.

此外,您还可以检查 更新:

实际上不确定特定设计的真正原因.我刚刚阅读了任务写作文件.并编写一个简单的MyDelete任务进行研究.

Actually not sure the real reason of the particular design. I've just read the Task Writing document. And write a simple MyDelete task to research.

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;
        }
    }

然后将以下脚本添加到项目文件中:

Then I add the script below into project file:

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

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

构建输出应类似于:

The build output should be like:

对于大多数任务,我的猜测是该属性是字符串,因此包含通配符的输入是字符串变量"path *.*",该任务的代码直接无法识别该变量 .

My guess is for most tasks, the property is string, so the input which contains a wildcard is a string variable "path*.*", which can't be recognized by the code of the task directly.

但是对于项,根据文档:项类型是项的命名列表,可以用作任务的参数.因此,输入的是像"xxx; xxx; xxx ..."这样的字符串,效果很好.

But for Item, according to document:Item types are named lists of items that can be used as parameters for tasks. So the input is string like "xxx;xxx;xxx..." which perform well.

我的更新只是进行深入的研究,难以回答有关设计的特殊原因.我认为,如果您确实想知道设计原因,则可能需要通过此链接.

My update is just to make a deep research, hard to answer the particular reason about the design. I think if you do want to know the design reason, you may need to ask some help from who supports the product by this link.

这篇关于如何在不使用ItemsGroup的情况下使用MSBuild Delete任务删除文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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