2011-08-30 67 views
1

我遇到麻煩讓我的MSBuild腳本轉換引用EF.Utility.CS.ttinclude的.tt文件。EF.Utility.CS.ttinclude和MSBuild

如果我從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

你試過調用texttransform.exe用-I開關, EF.Utility.CS.ttinclude的路徑? 該路徑可能是: C:\ Program Files文件\微軟的Visual Studio 10.0 \ Common7 \ IDE \擴展\微軟\實體框架工具\模板\包括\ 或 C:\ Program Files文件(x86)的\ Microsoft Visual Studio 10.0 \ Common7 \ IDE \ Extensions \ Microsoft \ Entity Framework Tools \ Templates \ Includes \ – Mir

回答

0

看來,模板你運行myttFile.tt失敗輸出任何作爲模板被執行的結果TransformText();

如果沒有看到myttFile.tt內部的邏輯是什麼,

的Visual Studio 11,如果你

設置<#模板調試=真正#>

,並添加 System.Diagnostics.Debugger.Launch(); 到您的模板的代碼部分,VS 11將啓動調試器,您可以調試您的t4。

對不起,剛剛對我明白。機會是你的模板依賴於Visual Studio作爲它的主機。在您的模板中的某處,您有hostspecific = true。

<#@模板hostspecific = 「真」 語言= 「C#」 #>

1

簡而言之:添加在TextTransform.exe -I標誌來解決這個問題,像這樣:

步驟1 : 創建一個環境變量映射到您的TextTransform的EF6包括像這樣: enter image description here

,這將創建一個變量VS140COMNTXTTRANSFORM日在視窗理解

第2步: 包括在TextTransform.exe命令-I標誌,像這樣:

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

偉大的工作對我而言,其他解決方案都不起作用 – RezaRahmati