我有一個T4模板,可以在我的項目中處理幾個.tt文件。我還定義了一些自定義類來幫助完成代碼轉換過程。構建期間生成T4代碼,自定義程序集引用
<#@ template language="C#" hostspecific="True" debug="True" #>
<#@ output extension="cs" #>
<#@ assembly name="System.Core.dll" #>
<#@ assembly name="$(TargetDir)\MyDependency.dll" #>
這適用於Visual Studio,我有一個VS宏,它正確定義$(TargetDir)。
現在,我想在構建過程中執行代碼生成過程。我說:
<TransformOnBuild>true</TransformOnBuild>
<OverwriteReadOnlyOutputFiles>true</OverwriteReadOnlyOutputFiles>
<IncludeDslT4Settings>true</IncludeDslT4Settings> <ItemGroup>
<T4ReferencePath Include="$(OutputPath)" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\TextTemplating\v10.0\Microsoft.TextTemplating.targets" />
我的構建運行,但我得到:
C:\ Program Files文件 (86)\的MSBuild \微軟\ VisualStudio的\ TextTemplating \ V10.0 \ Microsoft.TextTemplating。目標 (407):主機在嘗試解析程序集引用'$(TargetDir)\ MyDependency.dll'時嘗試解決 異常。轉換 將不會運行。引發以下異常: System.IO.FileLoadException:給定的程序集名稱或代碼庫爲 無效。在 System.Reflection.AssemblyName.nInit(RuntimeAssembly &組件, 布爾forIntrospection,布爾raiseResolveEvent)在 System.Reflection.AssemblyName.nInit()在 Microsoft.VisualStudio.TextTemplating.GlobalAssemblyCacheHelper.GetLocation:(0x80131047從HRESULT異常) (字符串 強名稱)在 Microsoft.VisualStudio.TextTemplating.Sdk.Host.GenericTextTemplatingHost.ResolveAssemblyReference(字符串 assemblyReference)在 Microsoft.VisualStudio.TextTemplating.Engine.ResolveAssemblyReferences(ITextTemplatingEngineHost 主機,TemplateProcessingSession會話)。 Line = -1,Column = -1
很明顯,它不會在Team build上下文中解析$(TargetDir)
。
我試着將TargetDir添加到我的構建配置的屬性組中,無濟於事。該值不會傳遞到T4代碼生成器的上下文中。
我不想使用環境變量。
如何在Team Build上下文中正確設置$(TargetDir)
?
奧列格Sych發表寫的MSBuild集成: HTTP://www.olegsych。com/2010/04/understanding-t4-msbuild-integration /#IncludeFolders。我不知道它是否能解決你的問題,但它似乎是一個很好的指導這個話題。 – FuleSnabel
是的,沒有骰子.. –