Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microsoft.TextTemplating.targets and FastUpToDate #9477

Open
innominateAtWork opened this issue Jun 6, 2024 · 4 comments
Open

Microsoft.TextTemplating.targets and FastUpToDate #9477

innominateAtWork opened this issue Jun 6, 2024 · 4 comments
Assignees
Labels
Feature-Up-to-date Build up-to-date check that avoids shelling out to MSBuild unless necessary. Triage-Investigate Reviewed and investigation needed by dev team

Comments

@innominateAtWork
Copy link

innominateAtWork commented Jun 6, 2024

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.
@innominateAtWork
Copy link
Author

innominateAtWork commented Jun 6, 2024

Actually the work around is just

<ItemGroup>
  <UpToDateCheckInput Include="**\*.tt" />
</ItemGroup>

the .tt files just need to be compared to the main set of outputs

It still would be nice if this was included in Microsoft.TextTemplating.targets

@haileymck haileymck assigned haileymck and drewnoakes and unassigned haileymck Jun 13, 2024
@haileymck haileymck added Feature-Up-to-date Build up-to-date check that avoids shelling out to MSBuild unless necessary. Triage-Investigate Reviewed and investigation needed by dev team labels Jun 13, 2024
@drewnoakes
Copy link
Member

I agree with your analysis here. Another option would be to use something like UpToDateCheckBuilt with Original metadata, so that the.tt file would be compared directly with its corresponding .cs file (given it's a 1:1 correspondence).

Microsoft.TextTemplating.targets is not defined in this repo, nor owned by this team. Could you file a feedback ticket with this suggestion? I will try and find the correct owner internally and route it to them.

@drewnoakes
Copy link
Member

Per https://stackoverflow.com/q/77024759/24874, the generated files are considered Compile items, and they are modified after the build starts, so you can end up with overbuild resembling:

Input Compile item 'MyFile.generated.cs' has been modified since the last successful build started, not up-to-date.

As these are Compile items, and not UpToDateCheck* items, they cannot be removed from the FUTDC without also removing them from the language service.

We could consider adding support for metadata on FUTDC items (Compile, Content, etc.) that causes the FUTDC to ignore them.

For example:

<ItemGroup>
  <Compile Update="*.generated.cs" IgnoreInFastUpToDateCheck="true" />
</ItemGroup>

@drewnoakes
Copy link
Member

Here's a repo showing an example of generating source during builds that works with the FUTDC: https://github.com/drewnoakes/generate-code-sample

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature-Up-to-date Build up-to-date check that avoids shelling out to MSBuild unless necessary. Triage-Investigate Reviewed and investigation needed by dev team
Projects
None yet
Development

No branches or pull requests

3 participants