visual-studio-2013 - T4 包括安装 VS2013 更新 3 后破坏的指令

标签 visual-studio-2013 include t4

更新到 后Visual Studio 2013 更新 3 ,以下代码中的 T4模板休息。

<#@ include file="../File1.tt" #>

它在所有以前版本的 VS 中都按预期工作。
通过此更新,所有变体:
<#@ include file="../File1.tt" #>
<#@ include file="..\File1.tt" #>
<#@ include file="..\\File1.tt" #>

失败并出现以下错误:
There was an error loading the include file '..\\File1.tt'. The transformation will not    be run. The following Exception was thrown:
System.ArgumentException: The path is not of a legal form.
  at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
  at System.IO.Path.GetFullPathInternal(String path)
  at System.IO.Path.GetFullPath(String path)
  at Microsoft.VisualStudio.TextTemplating.Engine.VisitedFiles.Visit(String fileLocation)
  at Microsoft.VisualStudio.TextTemplating.Engine.ProcessIncludeDirective(Directive directive, ITextTemplatingEngineHost host, VisitedFiles includedFiles) in line: 234 in file: C:\...\mytemplate.tt

任何已知的解决方法或解决此问题的方法?

最佳答案

找到根本原因。

实现接口(interface)时ITextTemplatingEngineHost实现的方法之一是:

public bool LoadIncludeText(
              string requestFileName, out string content, out string location)

之前的所有先前版本中VS2013 更新 3 返回 location 中的有效文件名不需要作为输出的参数。其实我们发string.Empty .

根据 documentation如果模板不是基于文件系统的,则该值可以为空。请参阅文档引用:

location Type: String
A String that contains the location of the acquired text. If the host searches the registry for the location of include files or if the host searches multiple locations by default, the host can return the final path of the include file in this parameter. The host can set the location to Empty if the file could not be found or if the host is not file-system based.



但是在更新 3 中,有些东西发生了变化,T4 引擎检查并期望 location参数为非空文件路径。 String.Empty value 导致原始注释异常。

作为临时解决方法:将有效文件名传递给 location方法参数LoadIncludeText实现时ITextTemplateEngineHost避免异常。

感谢 @rubenjmarrufo在寻找错误。

更新:微软确认的错误。它将在更新 4 上修复。评论的解决方法是有效的。

关于visual-studio-2013 - T4 包括安装 VS2013 更新 3 后破坏的指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25377848/

相关文章:

c++ - 如何在 cmake 中检查给定的头文件是否可用于 C++ 项目

php - WordPress - get_template_directory() 返回父主题的 url

css - jsp 函数标签来替换 '

c++ - 未找到 GetAddrInfo 标识符

c# - 无法增加堆栈大小 Visual Studio 2013 C#

c++ - <Struct at NULL> 与 "Struct is null"相同吗?

c# - 使 .Net 3.5 应用程序与 .Net 4.0 应用程序对话的最稳定方式

entity-framework - 使用 T4 生成代码时,EdmFunction 中的 Entity Framework 架构始终为空

c# - 如何通过t4生成自定义类?

c# - VisualStudio.Net 引用不起作用