Using UpToDateCheckInput in VS

The Up-to-date Check feature in Visual Studio checks if a project needs a full rebuild or not. The main factor it checks is if any source file has changed since the last build. You can use the UpToDateCheckInput and FastUpToDateCheckIgnoresKinds properties in csproj to have it ignore specific files. I’ll show an example of how to do that. In my case, I had to make it ignore auto-generated text templating output.

Note: This only seems to be a problem in SDK-style projects (the default in new versions of .NET). I tested the problem and fix in VS2022.

1 – Turn on Up-to-date Check logging

Before making changes, I suggest turning on the Up-to-date Check logging so you can see what’s causing VS to do full rebuilds.

  • Open the Visual Studio options (Tools > Options…).
  • Go to Projects and Solutions > SDK-Style Projects.
  • Change the Logging Level to Verbose
  • Click OK.
Visual Studio options > Projects and Solutions > SDK-Style Projects. Logging Level = Verbose.

This logs to the build output window. Here’s an example of what this looks like in my case:

Visual Studio build output window showing the Up-to-date Check

In my case, I had a text template generating output during the build. This caused subsequent builds to be out of date (according to the Up-to-Date Check), therefore triggering a full rebuild every time.

2 – Ignore the text template generated output

To make the Up-to-Date Check ignore a source file, add two properties to csproj:

  • UpToDateCheckInput. Specify a value for the Kind attribute, such as “GeneratedDuringBuild”.
  • FastUpToDateCheckIgnoresKinds. Put the value you used for Kind in this property (i.e. “GeneratedDuringBuild”).

Here’s an example of adding these properties:

<Project Sdk="Microsoft.NET.Sdk">

  <!-- rest of .csproj -->
  
	<ItemGroup>
		<UpToDateCheckInput Include="VersionAutoIncrement.cs" Kind="GeneratedDuringBuild" />
	</ItemGroup>
	<PropertyGroup>
		<FastUpToDateCheckIgnoresKinds>GeneratedDuringBuild</FastUpToDateCheckIgnoresKinds>
	</PropertyGroup>
	
</Project>
Code language: HTML, XML (xml)

Now right-click the project and Unload Project, then Reload Project. For some reason, this is necessary to make the Up-to-date Check pay attention to the FastUpToDateCheckIgnoresKinds property (thanks to reader Brad V. for pointing this out!).

Build once. It’ll do a rebuild because you changed the csproj file. Then click Build again. It shouldn’t rebuild this time because it’s ignoring the source file you put in UpToDateCheckInput. Notice it says Project is up to date.

Visual Studio Up-to-date Check correctly showing the project is up-to-date and doesn't need to rebuild

FastUpToDateCheckIgnoresKinds feature availability

The FastUpToDateCheckIgnoresKinds feature was added recently to the project system repository. It appears this is available starting in VS2022. I tested on VS2019 and it didn’t work.

Leave a Comment