如何在MSBuild中编译TypeLite T4模板
我想在构建过程中使用ign TypeLite自动为所有C#dto创建如何在MSBuild中编译TypeLite T4模板,msbuild,typescript,code-generation,t4,typelite,Msbuild,Typescript,Code Generation,T4,Typelite,我想在构建过程中使用ign TypeLite自动为所有C#dto创建.d.ts文件。我的Contract.tt是安装Nuget软件包后的原始文件,略为缩小: <#@ template debug="true" hostspecific="True" language="C#" #> <#@ assembly name="TypeLite.dll" #> <#@ assembly name="TypeLite.Net4.dll" #>
.d.ts
文件。我的Contract.tt是安装Nuget软件包后的原始文件,略为缩小:
<#@ template debug="true" hostspecific="True" language="C#" #>
<#@ assembly name="TypeLite.dll" #>
<#@ assembly name="TypeLite.Net4.dll" #>
<#@ assembly name="My.Contract.dll" #>
<#@ import namespace="TypeLite" #>
<#@ import namespace="TypeLite.Net4" #>
<#@output extension=".d.ts"#>
<#@include file="Manager.ttinclude"#>
<#
var manager = Manager.Create(Host, GenerationEnvironment);
var ts = TypeScript.Definitions()
.WithReference("Enums.ts")
.ForLoadedAssemblies();
#>
<#= ts.Generate(TsGeneratorOutput.Properties) #>
<# manager.StartNewFile("Enums.ts"); #>
<#= ts.Generate(TsGeneratorOutput.Enums) #>
<# manager.EndBlock(); #>
<# manager.Process(true); #>
我在MSbuild过程中添加了以下代码:
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">12.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<TransformOnBuild>true</TransformOnBuild>
</PropertyGroup>
<ItemGroup>
<T4ReferencePath Include="$(SolutionDir)\My.Contract\bin\$(Configuration)">
<InProject>False</InProject>
</T4ReferencePath>
<None Include="$(SolutionDir)\Scripts\Contract.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<OutputFilePath>$(SolutionDir)\Scripts</OutputFilePath>
</None>
</ItemGroup>
<Import Project="$(VSToolsPath)\TextTemplating\Microsoft.TextTemplating.targets" />
12
$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
真的
假的
文本模板文件生成器
$(SolutionDir)\r脚本
但不幸的是,我收到了这个错误:
Error 14 Running transformation: System.ArgumentNullException: Value cannot be null.
Parameter name: Could not obtain DTE from host
at Microsoft.VisualStudio.TextTemplating<cut>.GeneratedTextTransformation.Manager.VSManager..ctor
运行转换时出现错误14:System.ArgumentNullException:值不能为null。
参数名称:无法从主机获取DTE
在Microsoft.VisualStudio.TextTemplating.GeneratedTextTransformation.Manager.VSManager..ctor
看起来T4模板只能在VisualStudio中执行。有没有办法使用MSBuild运行TypeLite编译?问题出在中,它负责将T4输出拆分为多个文件,并自动将它们添加到项目中。这需要不是中MSBuild目标一部分的DTE 因此,我刚刚删除了
manager
,并创建了两个单独的模板。而不是Contract.tt
我得到了:
Enums.tt:
<#@ template debug="false" hostspecific="True" language="C#" #>
<#@ assembly name="TypeLite.dll" #>
<#@ assembly name="TypeLite.Net4.dll" #>
<#@ assembly name="CC.Business.Contract.dll" #>
<#@ import namespace="TypeLite" #>
<#@ import namespace="TypeLite.Net4" #>
<#@output extension=".ts"#>
<#
var ts = TypeScript.Definitions()
.ForLoadedAssemblies();
#>
<#= ts.Generate(TsGeneratorOutput.Enums) #>
<#@ template debug="false" hostspecific="True" language="C#" #>
<#@ assembly name="TypeLite.dll" #>
<#@ assembly name="TypeLite.Net4.dll" #>
<#@ assembly name="CC.Business.Contract.dll" #>
<#@ import namespace="TypeLite" #>
<#@ import namespace="TypeLite.Net4" #>
<#@output extension=".d.ts"#>
<#
var ts = TypeScript.Definitions()
.WithReference("Enums.ts")
.ForLoadedAssemblies();
#>
<#= ts.Generate(TsGeneratorOutput.Properties) #>
和型号。tts:
<#@ template debug="false" hostspecific="True" language="C#" #>
<#@ assembly name="TypeLite.dll" #>
<#@ assembly name="TypeLite.Net4.dll" #>
<#@ assembly name="CC.Business.Contract.dll" #>
<#@ import namespace="TypeLite" #>
<#@ import namespace="TypeLite.Net4" #>
<#@output extension=".ts"#>
<#
var ts = TypeScript.Definitions()
.ForLoadedAssemblies();
#>
<#= ts.Generate(TsGeneratorOutput.Enums) #>
<#@ template debug="false" hostspecific="True" language="C#" #>
<#@ assembly name="TypeLite.dll" #>
<#@ assembly name="TypeLite.Net4.dll" #>
<#@ assembly name="CC.Business.Contract.dll" #>
<#@ import namespace="TypeLite" #>
<#@ import namespace="TypeLite.Net4" #>
<#@output extension=".d.ts"#>
<#
var ts = TypeScript.Definitions()
.WithReference("Enums.ts")
.ForLoadedAssemblies();
#>
<#= ts.Generate(TsGeneratorOutput.Properties) #>
让T4模板在构建中运行的唯一方法是安装VS SDK,然后建模SDK,不是吗?我是否遗漏了什么?我收到了以下错误:“未能找到编译转换:元数据文件“$(TargetDir)TypeLite.dll”。行=0,列=0”。有什么想法吗?我想我可能把T4ReferencePath设置错了?