MSbuild up-to-date check for generated files does not work as needed
12:27 01 Sep 2023

I have a c# project which includes several generated files (by T4) which are later included in compilation. The generation of code files itself works fine, but unfortunately incremental build sees generated files as a 'changes since last build' and re-builds the project each time. (For me it is a problem, since a large part of solution is rebuilt each time).

The warning from MSbuild looks like

The project does not appear up-to-date after a successful build: Input Compile item '...\DtoGenerator.generated.cs' has been modified since the last successful build started, not up-to-date. See https://aka.ms/incremental-build-failure.

Related part of the *csproj:

  
          
          
          
  
    
        
    

I added ´UpToDateCheck*´ as per link proposed in warning, but it does not seem to work.

I have also seen the other proposed solution where "

Have anyone encountered similar problem? How can I change the *.csproj to have the files generated before build and included during compilation, but excluding them from incremental build check?

msbuild t4 csproj incremental-build