0

我有几组项目,部分相交。所有集合都包含源文件。每个这样的集合都必须单独编译。我希望通过使用元数据来实现这一点,但我就是想不出办法。以下是我的设置:

<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>

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

4

1 回答 1

0

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

  1. Target Filter1 按身份复制项目,但不保留原始元数据。
  2. Target Filter2 复制包含元数据的项目,然后删除我不想要的项目。Filter2 的优点是您拥有所有原始元数据。

<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>

于 2013-07-15T19:34:53.707 回答