EF.Utility.CS.ttinclude和MSBuild

时间:2011-08-30 15:20:42

标签: entity-framework-4 msbuild t4

我无法让我的MSBuild脚本转换一个引用EF.Utility.CS.ttinclude的.tt文件。

如果我在VS2010中运行代,它运行正常,但是当我通过命令行运行自定义构建脚本时,我得到了。

 TextTransform "C:\SourceControl\SVN\PathToFile\myttFile.tt"
C:\SourceControl\SVN\PathToFile\myttFile.tt(9,4): error : There was an error loading the include file 'EF.Utility.CS.ttinclude'. The transformation will not be run. The following Exception was thrown: [C:\SourceControl\SVN\PathToBuildScript\build.xml]
  System.IO.FileNotFoundException: Could not find file 'C:\SourceControl\SVN\PathToFile\EF.Utility.CS.ttinclude'.
  File name: 'C:\SourceControl\SVN\PathToFile\EF.Utility.CS.ttinclude'
     at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
     at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
     at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
     at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)
     at System.IO.StreamReader..ctor(String path)
     at Microsoft.VisualStudio.TextTemplating.CommandLine.CommandLineHost.ReadFileContent(String fileName)
     at Microsoft.VisualStudio.TextTemplating.CommandLine.CommandLineHost.LoadIncludeText(String requestFileName, String& content, String& location)
     at Microsoft.VisualStudio.TextTemplating.Engine.ProcessIncludeDirective(Directive directive, ITextTemplatingEngineHost host)
C:\SourceControl\SVN\PathToBuildScript\build.xml(30,5): error MSB3073: The command "TextTransform "C:\SourceControl\SVN\PathToFile\myttFile.tt"" exited with code 1.

如果我引用EF.Utility.CS.ttinclude的绝对路径,我得到:

  TextTransform "C:\SourceControl\SVN\PathToFile\myttFile.tt"
EXEC : error : An expression block evaluated as Null [C:\SourceControl\SVN\PathToBuildFile\build.xml]
     at Microsoft.VisualStudio.TextTemplating.ToStringHelper.ToStringWithCulture(Object objectToConvert)
     at Microsoft.VisualStudio.TextTemplatinga265b58e2b114039856ebd504775f376.GeneratedTextTransformation.TransformText() in c:\SourceControl\SVN\PathToFile\myttFile.tt:line 77
     at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(TemplateProcessingSession session, String source, ITextTemplatingEngineHost host, String& result)
C:\SourceControl\SVN\PathToBuildFile\build.xml(30,5): error MSB3073: The command "TextTransform "C:\SourceControl\SVN\PathToFile\myttFile.tt"" exited with code 1.

任何帮助都会很棒:)

2 个答案:

答案 0 :(得分:2)

简而言之:在TextTransform.exe中添加-I标志来解决这个问题,如下所示:

第1步: 创建一个映射到TextTransform的EF6 Include的环境变量,如下所示: enter image description here

将创建Windows理解的 VS140COMNTXTTRANSFORM 变量

第2步: TextTransform.exe 命令中包含 -I 标志,如下所示:

TextTransform.exe -I "%VS140COMNTXTTRANSFORM%" -out filename.tt

答案 1 :(得分:0)

看来您运行myttFile.tt的模板因输出模板而输出的内容失败了TransformText();

如果没有看到myttFile.tt中的逻辑内容,真的无法说清楚。

Visual Studio 11(如果您

set<#template debug = true#>

并添加 System.Diagnostics.Debugger.Launch(); 在模板的代码部分,VS 11将启动调试器,您可以调试t4。

抱歉,刚刚见到我。机会是你的模板依赖于visual studio作为它的主机。在模板的某个地方,你有hostspecific = true。

<#@ template hostspecific =“true”language =“C#”#>