更新到 后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/