Add Custom Metadata to Already-defined ItemGroup from Another ItemGroup

后端 未结 1 852
抹茶落季
抹茶落季 2021-01-18 15:45

I have the following:


  




        
相关标签:
1条回答
  • 2021-01-18 16:24

    This can be achieved by using target batching to add your Version member to the metadata. This involves moving your ReadLinesFromFile operation to its own target, using the @(Files) ItemGroup as an input.

    This causes the target to be executed for each item in your ItemGroup, allowing you to read the contents (i.e. version number) from each individual file and subsequently update that item to add the Version metadata:

    <Project DefaultTargets="OutputFilesAndVersions" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <ItemGroup>
          <Files Include="C:\Versioning\**\file.version" />
        </ItemGroup>
        <Target Name="OutputFilesAndVersions" DependsOnTargets="RetrieveVersions">
            <Message Text="@(Files->'%(Identity): %(Version)')" />
        </Target>
        <Target Name="RetrieveVersions" Inputs="@(Files)" Outputs="%(Files.Identity)">
            <ReadLinesFromFile File="%(Files.Identity)">
              <Output TaskParameter="Lines" PropertyName="_Version"/>
            </ReadLinesFromFile>
            <PropertyGroup>
                <MyFileName>%(Files.Identity)</MyFileName>
            </PropertyGroup>
            <ItemGroup>
                <Files Condition="'%(Files.Identity)'=='$(MyFileName)'">
                    <Version>$(_Version)</Version>
                </Files>
            </ItemGroup>  
        </Target>
    </Project>
    
    0 讨论(0)
提交回复
热议问题