【问题标题】:How to pass items one by one to another msbuild task?如何将项目一个接一个地传递给另一个 msbuild 任务?
【发布时间】:2011-12-15 12:53:08
【问题描述】:

我们有 x, y ,z 属性文件和一个 master.properties 文件

现在,我已经在我的 master.properties 文件中编写了一些 itemgroup,如下所示,并将这个 itemgroup 传递给 msbuild 目标,以便它像 foreach 一样工作。

项目组:

 <Components Include="Y:\Build\X.Properties">
      <ComponentName>X</ComponentName>
    </Components>

    <Components Include="Y:\Build\Y.Properties">
      <ComponentName>Y</ComponentName>
    </Components>

   <Components Include="Y:\Build\Z.Properties">
      <ComponentName>Z</ComponentName>
    </Components>



<Target Name="BuildAll" Inputs="@(Components)" Outputs="%(Identity).Dummy">

    <MSBuild Projects="@(Components)" 

             Targets="BuildComponent" />

  </Target>

现在我想要一个 txt 文件,其中组件名称将像这样给出

X 是的

它应该只构建 X 和 Y。

我正在尝试使用 ReadLinesFromFile ,但我无法逐个传递组件。

例如:

 <ReadLinesFromFile File="Allcomponent.txt">
      <Output TaskParameter="Lines" ItemName="AllComponent" />
  </ReadLinesFromFile>

然后我想将itemgroup中的组件一一传递来调用Msbuild任务。

如何解决?

【问题讨论】:

  • PowerShell 从何而来?
  • @Abbas:我刚刚从这个问题中删除了 powershell 标签...

标签: .net msbuild


【解决方案1】:

您的问题不是很清楚,尤其是在“我无法通过一个组件”之后。

您可以像这样访问 ItemGroup 中每个项目的自定义元数据:

<Target Name="BuildAll" Inputs="@(Components)" Outputs="%(Identity).Dummy">
    <MSBuild Projects="%(Identity)" 
             Targets="%(ComponentName)" />
</Target>

【讨论】:

    【解决方案2】:

    我终于找到了解决方案。解决方法如下

    我应该使用组件名称创建属性。

    <X>Y:\Build\X.Properties</X>
    <Y>Y:\Build\Y.Properties</Y>
    <Z>Y:\Build\Z.Properties</Z>
    

    在 Msbuild 任务中,我应该遵循如下

    <Target Name="BuildAll" >
    
        <ReadLinesFromFile  File="$(AllComponents)">
          <Output TaskParameter="Lines" ItemName="AllComponents"/>
        </ReadLinesFromFile>
    
        <MSBuild Projects="$(%(AllComponents.Identity))"
    
                 Targets="BuildComponent" />
    
    </Target>
    

    现在它将构建我通过文本文件传递的组件。

    【讨论】:

      猜你喜欢
      • 2011-02-26
      • 2019-03-07
      • 1970-01-01
      • 1970-01-01
      • 2012-12-25
      • 1970-01-01
      • 2023-01-24
      • 2017-03-22
      • 1970-01-01
      相关资源
      最近更新 更多