根据元数据选择项目组

时间:2013-07-04 12:34:57

标签: visual-studio msbuild

我有几组项目,集合部分相交。所有集都包含源文件。每个这样的集合必须单独编译。我希望实现这一目标的方式是通过使用元数据,但我无法弄清楚方法。以下是我的设置:

<Content Include="src\Source.ts">
  <Integration>integration</Integration>
  <Development>development</Development>
</Content>
... <!-- more sources -->
<DeployLabel Include="deploy\integration\foo.js">
  <Dir>integration\</Dir>
</DeployLabel>
... <!-- more targets --->
<DeployLabel Include="deploy\integration\bar.js">
  <Dir>development\</Dir>
</DeployLabel>
<Target Inputs="@(DeployLabel)" Name="GenericDeploy" Outputs="%(Identity).Dummy">
    <PropertyGroup>
      <Deployroot>deploy\%(DeployLabel.Dir)</Deployroot>
    </PropertyGroup>
    <Message Text="Deploying: $$(Deploydir)"/>
    <!-- how to select here only the TypeScriptCompile files
         such that have metadata matching DeployLabel.Dir -->
    <Exec Command="tsc --target ES3 -c -d --out $$(Deployroot) @(TypeScriptCompile -&gt;'&quot;%(fullpath)&quot;', ' ')"/>
  </Target>

我正在生成项目文件,所以如果它可以以不同方式完成,但是以自动方式完成 - 那也没关系。

1 个答案:

答案 0 :(得分:0)

您可以使用条件和批处理来过滤项目。 如果我需要项目的元数据,我会根据情况使用两种方法。

  1. 目标过滤器1按标识复制项目,但不保留原始元数据。
  2. 目标过滤器2复制包含元数据的项目,然后删除我不想要的项目。 Filter2的优点是您拥有所有原始元数据。
  3. <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <ItemGroup>
            <DeployLabel Include="deploy\integration\foo.js">
                <Dir>integration\</Dir>
                <T>1</T>
            </DeployLabel>
            <DeployLabel Include="deploy\integration\foo2.js">
                <Dir>integration\</Dir>
                <T>2</T>
            </DeployLabel>
            <DeployLabel Include="deploy\integration\foo3.js">
                <Dir>integration\</Dir>
                <T>3</T>
            </DeployLabel>
            <DeployLabel Include="deploy\integration\bar.js">
                <Dir>development\</Dir>
                <T>0</T>
            </DeployLabel>
        </ItemGroup>
    
        <Target Name="Filter1">
            <ItemGroup>
                <_DeployLabelHelper Include="%(DeployLabel.Identity)" Condition=" 'integration\' == '%(DeployLabel.Dir)' " />
            </ItemGroup>
            <Message Text="@(_DeployLabelHelper->'%(Identity):%(T)')"/>
        </Target>
    
        <Target Name="Filter2">
            <ItemGroup>
                <_RemovalHelper Include="%(DeployLabel.Identity)" Condition=" 'integration\' != '%(DeployLabel.Dir)' " />
                <_DeployLabelHelper Include="@(DeployLabel)" />
                <_DeployLabelHelper Remove="@(_RemovalHelper)" />
            </ItemGroup>
    
            <Message Text="@(_DeployLabelHelper->'%(Identity):%(T)')"/>
        </Target>
    </Project>
    

    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <DeployLabel Include="deploy\integration\foo.js"> <Dir>integration\</Dir> <T>1</T> </DeployLabel> <DeployLabel Include="deploy\integration\foo2.js"> <Dir>integration\</Dir> <T>2</T> </DeployLabel> <DeployLabel Include="deploy\integration\foo3.js"> <Dir>integration\</Dir> <T>3</T> </DeployLabel> <DeployLabel Include="deploy\integration\bar.js"> <Dir>development\</Dir> <T>0</T> </DeployLabel> </ItemGroup> <Target Name="Filter1"> <ItemGroup> <_DeployLabelHelper Include="%(DeployLabel.Identity)" Condition=" 'integration\' == '%(DeployLabel.Dir)' " /> </ItemGroup> <Message Text="@(_DeployLabelHelper->'%(Identity):%(T)')"/> </Target> <Target Name="Filter2"> <ItemGroup> <_RemovalHelper Include="%(DeployLabel.Identity)" Condition=" 'integration\' != '%(DeployLabel.Dir)' " /> <_DeployLabelHelper Include="@(DeployLabel)" /> <_DeployLabelHelper Remove="@(_RemovalHelper)" /> </ItemGroup> <Message Text="@(_DeployLabelHelper->'%(Identity):%(T)')"/> </Target> </Project>