【问题标题】:MSBUILD Task Items in subdirectories: Are incremental builds not possible on these?子目录中的 MSBUILD 任务项:不能在这些上进行增量构建吗?
【发布时间】:2008-10-09 16:06:24
【问题描述】:

我有一个简单的 Word 到 Pdf 转换器作为 MSBuild 任务。该任务将 Word 文件 (ITaskItems) 作为输入,将 Pdf 文件 (ITaskItems) 作为输出。该脚本使用 Target 转换进行转换:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
  <UsingTask AssemblyFile="$(MSBuildExtensionsPath)\MyTasks.dll" TaskName="MyTasks.DocToPdf" />
  <Target Name="Build" DependsOnTargets="Convert" />
  <Target Name="Convert"
          Inputs="@(WordDocuments)"
          Outputs="@(WordDocuments->'%(FileName).pdf')">
    <DocToPdf Inputs="@(WordDocuments)"
              Outputs="%(FileName).pdf">
      <Output TaskParameter="ConvertedFiles" ItemName="PdfDocuments" />
    </DocToPdf>
  </Target>
  <ItemGroup>
    <WordDocuments Include="One.doc" />
    <WordDocuments Include="SubDir\Two.doc" />

    <WordDocuments Include="**\*.doc" />
  </ItemGroup>
</Project>

发生的情况是 SubDir\Two.doc 在每次增量构建时都会被转换,而 One.doc 不会(即 MSBuild 正确跳过该文件,因为它已经被转换)。如果我使用递归项目规范(上面的第三个),我会得到相同的行为(即 One.doc 只有在 PDF 过期或丢失时才会被转换,但子目录中的所有文档总是会被转换)。

我在这里做错了什么?

【问题讨论】:

    标签: msbuild


    【解决方案1】:

    我发现了问题。事实证明,我在 Task 中有一些逻辑,它将为 PDF 文件指定的任何相对路径转换为绝对路径。一旦我删除它并将脚本更改为:

      <Target Name="Convert"
              Inputs="@(WordDocuments)"
              Outputs="@(WordDocuments->'%(RelativeDir)%(FileName).pdf')">
        <DocToPdf Inputs="%(WordDocuments.Identity)"
                  Outputs="%(RelativeDir)%(FileName).pdf">
          <Output TaskParameter="ConvertedFiles" ItemName="PdfDocuments" />
        </DocToPdf>
      </Target>
    

    我得到了我预期的行为。

    【讨论】:

      【解决方案2】:

      这是我对通过子目录递归找到的项目执行增量构建的任务示例:

        <Target Name="Build" Inputs="@(RequestTextFiles)" Outputs="@(RequestTextFiles -> '%(Rootdir)%(Directory)%(Filename).out')">
      
          <DoSomething SourceFiles="@(RequestTextFiles)" />
      
        </Target>
      

      这将 1:1 与一个输入文件和一个具有相同名称的输出文件映射,输出到具有不同扩展名的相同路径,在本例中为“out”。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-12-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-27
        相关资源
        最近更新 更多