如何将PropertyGroup/ItemGroup中的可变项数传递给msbuild脚本

如何将PropertyGroup/ItemGroup中的可变项数传递给msbuild脚本,msbuild,msbuild-task,msbuild-propertygroup,Msbuild,Msbuild Task,Msbuild Propertygroup,请仔细阅读,直到我把问题说清楚。我正在尝试实现一个自定义msbuild任务,该任务将从msbuild脚本接受数量可变的输入参数。我知道海关任务中的输入参数数组 public ITaskItem[] ArrayofItems { get; set; } 可以使用propertygroup/itemgroup按如下方式声明它们 <PropertyGroup> <Item1>1</Item> <Item2>2</Item> <Item

请仔细阅读,直到我把问题说清楚。我正在尝试实现一个自定义msbuild任务,该任务将从msbuild脚本接受数量可变的输入参数。我知道海关任务中的输入参数数组

public ITaskItem[] ArrayofItems { get; set; }
可以使用propertygroup/itemgroup按如下方式声明它们

<PropertyGroup>
<Item1>1</Item>
<Item2>2</Item>
<Item3>3</Item>
<Item4>4</Item>
<Item5>5</Item></PropertyGroup>

 <ItemGroup>
<File Include="1"></File>
<File Include="2"></File>
<File Include="3"></File>
<File Include="4"></File>
<File Include="5"></File>  </ItemGroup>

1.
2.
3.
4.
5.
然后从VS2010命令行,我可以设置/覆盖属性,如下所示

msbuild somefile.csproj/t:MyTarget/p:Item1=Name1;Item2=名称2…等

我的问题是:-是否可以在生成文件中声明propertygroup/itemgroup的变量号,以便我可以使用propertygroup/itemgroup从msbuild命令行传入类似以下内容的“n”变量参数

msbuild somefile.csproj/t:MyTarget/p:Item1=Name1;Item2=名称2;ItemN=NameN('N'仅用于说明)

这可能吗


提前感谢,我们将非常感谢您的帮助。

如果您这样称呼您的构建项目

> msbuild My.proj /p:ItemProperty="1;2;3;4;5"
这个项目就是这样做的

<ItemGroup>
    <FromProperty Include="$(ItemProperty)" />
</ItemGroup>
<Message Text="%(FromProperty.Identity)" />

…您实际上已将属性转换为项目数组。如果要转换为动态创建的属性,那么在脚本的其余部分中引用它们将不是一个简单的方法,因为在编写脚本之前,您不会知道它们的名称

摘自《把戏#30》,其中有许多关于这种操纵的详细信息