动态默认项目元数据

时间:2019-04-25 12:40:03

标签: msbuild msbuild-itemgroup

请考虑以下文件结构。 Things中的每个项目都包含以下元数据:

  • CustomData1是特定于项目的;
  • ComputedData取决于CustomData1,但转换本身始终是相同的(当然,我的实际情况是具有大量有用输出的广泛转换序列);
  • CustomData2取决于ComputedData

<?xml version="1.0" encoding="utf-8"?>
<Project
    ToolsVersion="15.0"
    xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
    DefaultTargets="Run"
>
    <ItemGroup>
        <Things Include="my-thing-1">
            <CustomData1>data1</CustomData1>
            <ComputedData>%(CustomData1)-computed</ComputedData> <!-- Common code -->
            <CustomData2>%(ComputedData)-used1</CustomData2>
        </Things>
        <Things Include="my-thing-2">
            <CustomData1>data2</CustomData1>
            <ComputedData>%(CustomData1)-computed</ComputedData> <!-- Common code -->
            <CustomData2>%(ComputedData)-used2</CustomData2>
        </Things>
    </ItemGroup>

    <Target Name="Run">
        <Message
            Importance="High"
            Text="Things contains:%0a@(Things -> '%09%(Identity): %(CustomData1), %(ComputedData), %(CustomData2)', '%0a')"
        />
    </Target>
</Project>

以上内容按预期工作,并输出:

Things contains:
    my-thing-1: data1, data1-computed, data1-computed-used1
    my-thing-2: data2, data2-computed, data2-computed-used2

到目前为止,太好了。现在,我正在尝试分解常见的ComputedData部分(最终导入到另一个文件中,然后导入该文件),但是找不到解决方法。

我一直在寻找ItemDefinitionGroups,令我惊讶的是,它可以基于众所周知的每项元数据定义自定义元数据。但是,基于自定义每个项目元数据的相同代码起作用:

<ItemDefinitionGroup>
    <Things>
        <!-- Produces `my-thing-1-computed-1` (success) -->
        <ComputedData1>%(Identity)-computed1</ComputedData1>
        <!-- Produces `-computed-2` (failure) -->
        <ComputedData2>%(CustomData1)-computed2</ComputedData2>
    </Things>
</ItemDefinitionGroup>

如何生成既取决于每个项目元数据又取决于其他每个项目元数据的默认项目元数据?

0 个答案:

没有答案