redwyre
redwyre

Reputation: 1109

How to create a custom task with a dependency for incremental build?

I have a build step that parses a csv file and generates numerous .cs files, and I am trying to make a build target that will let me generated them incrementally/only when the source file has changed.

I have created a Target (in TechTreeGenerator.targets):

  <Target Name="BuildTechTreeGenerator" BeforeTargets="BeforeBuild" Inputs="@(TechTree)" Outputs="$(ProjectDir)..\Mods\AutoGen\AutoGen.lastbuild">
    <TechTreeGenerator SourceCsv="@(TechTree)" OutputFolder="$(ProjectDir)..\Mods\AutoGen" TemplateFolder="$(ProjectDir)..\TechTreeTemplates">
      <Output TaskParameter="DestinationFiles" ItemName="CompileFiles"/>
    </TechTreeGenerator>

    <ItemGroup>
      <CompileFiles>
        <Link>%(Filename)%(Extension)</Link>
      </CompileFiles>
    </ItemGroup>
    <ItemGroup>
      <Compile Include="@(CompileFiles);" />
    </ItemGroup>
  </Target>

Where TechTreeGenerator is a code Task that runs the tool, and outputs a list of all files that are generated from the csv file (even if they haven't been re-generated). It also always outputs a "AutoGen.lastbuild" file to be compared with the csv file to tell if it needs to be rebuilt.

However, the lastbuild in the Outputs of the Target doesn't seem to have any affect. Deleting it doesn't rebuild the file.

Edit: I forgot to add in .csproj the project I'm referencing it as:

  <Import Project="TechTreeGenerator.targets" />
  <ItemGroup>
    <TechTree Include="..\EcoTechTree.csv" />
  </ItemGroup>

Upvotes: 2

Views: 217

Answers (1)

C.J.
C.J.

Reputation: 16091

Forget about the .lastbuild file. Just put as the input the .csv file. And put as the output an itemgroup the .cs files you generate.

<Target Name="bla" Inputs="@(CSVFilePath)" Outputs="@(YourCSfiles)">

Upvotes: 1

Related Questions