Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > T4 generating duplicate code file with different name
 

T4 generating duplicate code file with different name

I'm having a problem where my T4 (.tt) template generates my code file properly the first time but subsequent runs cause it to create yet another file with an numeric qualifier at the end resulting in failed builds due to duplicate code.

My template is named Entities.tt and after first pass I get:

Entities.tt
|_ Entities.cs

My second run yields:

Entities.tt
|_ Entities.cs
|_ Entities1.cs

At first I thought this was because I have version control hooked up to my solution and the file could have been read-only but I have verified this behavior as still happening by checking out the file to make it writable. I'm using SourceGear Vault (SourceGear Fortress package) for version control but again, I'm not entirely sure its caused by this. I would appreciate if someone could assist me in resolving this.

Also, this just started out of nowhere one day. It worked fine for a month or so and then out of the blue, just wanted to create new files with the number attached to it. Basically, I'm not sure a case to reproduce this from a working example or obviously get it to stop acting this way.

Thanks!
Diesel7633  Monday, July 06, 2009 8:02 PM

You're right; it doesn't look like a Vault issue. The only other problem I can think of is if the Entities.cs already existed in the project when you added Entities.tt. Check the project file to see if the <DependentUpon/> and <LastGenOutput/> properties are set correctly for Entities.cs and Entities.tt respectively. Here is what it should look like:

    <None Include="Entities.tt">
      <Generator>TextTemplatingFileGenerator</Generator>
      <LastGenOutput>Entities.cs</LastGenOutput>
    </None>    
    <None Include="Entities.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>Entities.tt</DependentUpon>
    </None>


Oleg
Oleg V. Sych  Monday, July 06, 2009 9:18 PM

This may be an issue with the Vault source controladd-in. Normal behavior for T4 template under source control is to automatically check out the output file and overwrite it. Do you get the same problem when the output file (Entities.cs) is checked out manually in advance?


Oleg
Oleg V. Sych  Monday, July 06, 2009 8:35 PM
Yes, actually, this is what finally prompted me to post to this forum. I assumed that it would because the file was read-only by Vault but I made it writable by checking it out, verified that I could edit it within VS editor, and it still just creates this new Entities1 .cs file. I'm not sure what other test scenarios I can run and can't really abandon our source control strategy because of a code-gen templating quirk.

Diesel7633  Monday, July 06, 2009 8:56 PM

You're right; it doesn't look like a Vault issue. The only other problem I can think of is if the Entities.cs already existed in the project when you added Entities.tt. Check the project file to see if the <DependentUpon/> and <LastGenOutput/> properties are set correctly for Entities.cs and Entities.tt respectively. Here is what it should look like:

    <None Include="Entities.tt">
      <Generator>TextTemplatingFileGenerator</Generator>
      <LastGenOutput>Entities.cs</LastGenOutput>
    </None>    
    <None Include="Entities.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>Entities.tt</DependentUpon>
    </None>


Oleg
Oleg V. Sych  Monday, July 06, 2009 9:18 PM
That did the trick! Thank you very much. Looks like this is what was in my project file (has the "1" in the file name)...

    <
None
 Include
=
"
Entities.tt
"
>

< Generator > TextTemplatingFileGenerator</ Generator >
< LastGenOutput > Entities1 .cs</ LastGenOutput >
</ None >
< None Include = " Entities.cs " >
< AutoGen > True</ AutoGen >
< DesignTime > True</ DesignTime >
< DependentUpon > Entities.tt</ DependentUpon >
</ None >
I changed the file to remove the 1 and it fixed it. I don't really know how I got it into that state but glad there is a solution for this (and it was rather simple after your suggestion).
Diesel7633  Tuesday, July 07, 2009 2:05 PM
Sorry, apparently copy and paste didn't display right between edit and view. Either way, really the only difference was the 1 in the name of the .cs file. Thanks again.
Diesel7633  Tuesday, July 07, 2009 3:36 PM

You can use google to search for other answers

Custom Search

More Threads

• GAX/GAT 2008 install problem
• Guidance Automation Toolkit installation problems
• Action to Add GAC folder to A (Vsd) Setup Project
• Installing Web Serivce Software Factory failing
• ABSF with Data Access Application Block
• Recipe Framework Error when using "Register Guidance Package"
• Web Services Software Factory install Error
• How to find a NULL in a dataset ?
• Error while using Guidance package in Ent Lib 3.0 for Strong Naming DLLs
• GAX Uninstall fails on Vista