VS2010 T4 does not automatically check generated files from TFS

I am trying to use such a simple scheme in my project:

Item.cs → contains a C # partial class with simple entity properties. He also set the "Custom Tool: T4ScriptFileGenerator" property, so he attaches the "grouped" Item.tt file to it. On its way, Item.generated.cs is generated, grouped by Item.tt. Thus, this leads to a grouped tree in the solution explorer:

Item.cs ˪Item.tt ˪Item.generated.cs 

Below you can see how it looks in the .csproj file.

The entire project is connected to the TFS 2010 workspace.

The problem is this:

When I edit Item.cs, the t4 engine recreates the Item.generated.cs file, but does not check it from tfs. It automatically checks only the first two levels of "grouped" files - Item.cs and its dependent Item.tt. Item.generated.cs is updated, but just overwritten without verification.

If I edit the Item.tt file or just click “Run the special tool” on it, two files are uploaded again: Item.tt and its dependent Item.generated.cs This is strange because it forces us to manually “run the custom tool” in each file * .tt after editing entity class files so that nothing is lost in TFS.

Q: Is there a way to get it to check the entire DependentUpon file tree when editing the main Item.cs?

Here's what it looks like in a .csproj source:

 <Compile Include="Entities\Item.cs"> <Generator>T4ScriptFileGenerator</Generator> <LastGenOutput>Item.tt</LastGenOutput> </Compile> <None Include="Entities\Item.tt"> <Generator>TextTemplatingFileGenerator</Generator> <AutoGen>True</AutoGen> <DesignTime>True</DesignTime> <DependentUpon>Item.cs</DependentUpon> <LastGenOutput>Item.codegen.cs</LastGenOutput> </None> <Compile Include="Entities\Item.codegen.cs"> <AutoGen>True</AutoGen> <DesignTime>True</DesignTime> <DependentUpon>Item.tt</DependentUpon> </Compile> 
+6
source share
2 answers

It's not very elegant, but you can always get VS to convert all the templates in the solution by clicking the "Convert All Templates" button at the top of the solution browser.

See my note on the original question, at least in VS2010 SP1, this seems to work, given the exact example of the project file fragment.

0
source
 /// <summary> /// (T4 template code to checkout a file path if necessary) /// </summary> /// <param name="fileName">The file name.</param> private void CheckoutFileIfRequired(String fileName) { var sc = this.dte.SourceControl; if (sc != null && sc.IsItemUnderSCC(fileName) && !sc.IsItemCheckedOut(fileName)) checkOutAction.EndInvoke(checkOutAction.BeginInvoke(fileName, null, null)); } 
0
source

Source: https://habr.com/ru/post/887689/


All Articles