Skip to content

Microsoft.TextTemplating.targets and FastUpToDate #9477

Open
@innominateAtWork

Description

@innominateAtWork

The Microsoft.TextTemplating.targets will run t4 transformations on any .tt files in your project on build.
https://learn.microsoft.com/en-us/visualstudio/modeling/code-generation-in-a-build-process?view=vs-2022&tabs=csharp

However if a .tt file (and nothing else) is changed then FastUpToDate will prevent a rebuild (and thus prevent the t4 transform from rerunning).

Ideally Microsoft.TextTemplating.targets will add .tt files and their outputs to the appropriate UpToDate item groups.

I tried to work around this with

<ItemGroup>
  <T4InFiles Include="**\*.tt" />
  <T4OutFiles Include="@(T4InFiles->'%(FullPath)'->Replace('.tt', '.cs'))" />     
        
  <UpToDateCheckInput Include="@(T4InFiles)" Set="T4Files" />
  <UpToDateCheckOutput Include="@(T4OutFiles)" Set="T4Files" />
</ItemGroup>

However that doesn't work if you have more than one .tt file you end up with a warning like the below and the build runs everytime.

WARNING: Potential build performance issue in 'MyProject.csproj'. The project does not appear up-to-date after a successful build: Input UpToDateCheckInput item 'C:\MyProject\File1.tt' is newer (2024-06-05 20:27:00.678) than earliest output 'C:\MyProject\File2.cs' (2024-06-05 20:26:28.652), not up-to-date. See https://aka.ms/incremental-build-failure.

Metadata

Metadata

Assignees

Labels

Feature-Up-to-dateBuild up-to-date check that avoids shelling out to MSBuild unless necessary.Triage-InvestigateReviewed and investigation needed by dev team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions