VS2010 T4 auto checkout of generated files from TFS fails
Asked Answered
L

2

6

I'm trying to use such simple scheme in my project:

Item.cs -> this contains c# partial class with simple entity properties. It has set also property "Custom Tool: T4ScriptFileGenerator" so it attaches "grouped" file Item.tt to it. Wich on its way generates Item.generated.cs, grouped to Item.tt. So it results in a grouped tree in solution explorer:

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

You can see below how it looks in .csproj file.

Whole project is connected to TFS 2010 workspace.

The problem is:

When I edit Item.cs, t4 engine recreates Item.generated.cs file, but does not check out it from tfs. It automatically checks out only first two levels of "grouped" files - Item.cs and its dependant Item.tt. The Item.generated.cs is updated, but simple overwriten, without checkout.

If I edit Item.tt file or just press "Run custom tool" on it - again two files are checked out: Item.tt and its dependant Item.generated.cs This is weird because forces us to manually "run custom tool" on every *.tt file after editing entity class files to ensure nothing is missing from TFS.

Q: Is there any way to force it to check out whole tree of DependentUpon files when main Item.cs is edited?

Here is how it looks in .csproj file 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>
Lure answered 10/5, 2011 at 6:49 Comment(1)
I'm not seeing the problem with a small repro of your solution in VS2010 SP1. I don't have 2010 without SP1 to hand, so it's possible that it's a project system fix in the service pack or a newer version of T4Toolbox, but it is working for me. Are you still seeing the issue? Also see my workaround as a simple answer below.Moxa
M
0

It's not very elegant, but you can always get VS to transform all the templates in the solution by hitting the "Transform All Templates" button at the top of the solution explorer.

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

Moxa answered 21/12, 2011 at 3:2 Comment(0)
W
-1
/// <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));
}
Wiring answered 19/9, 2017 at 5:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.