VS2010从TFS自动检出生成的文件失败

时间:2011-05-10 06:49:56

标签: visual-studio-2010 templates tfs t4 t4-toolbox

我正在尝试在我的项目中使用这样简单的方案:

Item.cs - >这包含具有简单实体属性的c#partial类。 它还设置了属性“Custom Tool:T4ScriptFileGenerator”,因此它将“分组”文件 Item.tt 附加到它。在路上生成 Item.generated.cs ,分组到 Item.tt 。 因此,它会在解决方案资源管理器中生成一个分组树:

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

您可以在下面看到它在.csproj文件中的显示效果。

整个项目已连接到TFS 2010工作区。

问题是:

当我编辑 Item.cs 时,t4引擎会重新创建 Item.generated.cs 文件,但不会从tfs中检出它。它只会自动检出前两个级别的“分组”文件 - Item.cs 及其相关的 Item.tt Item.generated.cs 已更新,但只是覆盖,无需结帐。

如果我编辑Item.tt文件或只是按“运行自定义工具” - 再次签出两个文件: Item.tt 及其依赖 Item.generated.cs < / EM> 这很奇怪,因为在编辑实体类文件后强制我们在每个* .tt文件上手动“运行自定义工具”,以确保TFS没有遗漏任何内容。

问:在编辑主Item.cs时,有没有办法强制它检查 DependentUpon 文件的整个树?

以下是它在.csproj文件源中的显示方式:

<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>

2 个答案:

答案 0 :(得分:0)

它不是很优雅,但是你可以通过点击解决方案资源管理器顶部的“转换所有模板”按钮来获得VS来转换解决方案中的所有模板。

在原始问题上看到我的注释,至少在VS2010 SP1中,考虑到确切的示例项目文件片段,这似乎有效。

答案 1 :(得分:0)

/// <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));
}