Why does my T4 template append a number to the file name?

This happens when Visual Studio gets itself confused and briefly decides that it can’t use Foo.cs as the output for some reason (usually hallucinatory), so it will use Foo1.cs instead, and then insists on remembering this setting.

The fix is to open the .csproj file in a text editor and locate the Foo.tt entry. This should have a sub-element called LastGenOutput. Change this back to Foo.cs, save the project file, and reopen it in VS.

And then — sigh — wait for it to happen again. You can see http://social.msdn.microsoft.com/Forums/en/linqtosql/thread/0c0f77a6-d712-43d2-a990-555df7960123 for more details, though nobody seems to be able to explain what causes VS to get into this state or how to stop it doing so…

Leave a Comment