问题描述
我有一个进程在我的项目数.TT文件的T4模板。我也有我定义了一些自定义的类来帮助与code转化的过程。
I have a T4 template that processes several .tt files in my project. I also have some custom classes I've defined to help with the code transformation process.
<#@ template language="C#" hostspecific="True" debug="True" #>
<#@ output extension="cs" #>
<#@ assembly name="System.Core.dll" #>
<#@ assembly name="$(TargetDir)\MyDependency.dll" #>
这工作在Visual Studio中,我有一个VS宏定义正确$(TARGETDIR)。
This works in Visual Studio, I have a VS Macro which defines $(TargetDir) correctly.
现在,我想在我的构建过程中执行code生成过程。我说:
Now, I want to perform the code generation process during my build process. I added:
<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" />
我的构建运行,但我得到:
My build runs, but I get:
C:\ Program Files文件 (86)\的MSBuild \微软\ VisualStudio中\ TextTemplating \ 10.0 \ Microsoft.TextTemplating.targets (407):试图解析主机抛出一个异常 集引用$(TARGETDIR)\ MyDependency.dll。改造 将不被运行。以下异常被抛出: System.IO.FileLoadException:给定的程序集名称或codeBase的是 无效。 (从HRESULT异常:0x80131047)在 System.Reflection.AssemblyName.nInit(RuntimeAssembly&安培;装配, 布尔forIntrospection,布尔raiseResolveEvent)在 System.Reflection.AssemblyName.nInit()在 Microsoft.VisualStudio.TextTemplating.GlobalAssemblyCacheHelper.GetLocation(字符串 强名称)在 Microsoft.VisualStudio.TextTemplating.Sdk.Host.GenericTextTemplatingHost.ResolveAssemblyReference(String assemblyReference)在 Microsoft.VisualStudio.TextTemplating.Engine.ResolveAssemblyReferences(ITextTemplatingEngineHost 主机,TemplateProcessingSession会话)。行= -1,列= -1
很显然,这不会解决 $(TARGETDIR)
在团队建设方面。
Obviously it won't resolve $(TargetDir)
in Team build context.
我尝试添加TARGETDIR到我的构建配置的属性组,但没有成功。此值好好尝试一下,通过传递给T4 code发电机的上下文
I tried adding TargetDir to my build configuration's property group, to no avail. This value doens't pass through to the context of the T4 Code Generator.
我不想使用环境变量。
如何设置 $(TARGETDIR)
正确的团队建设方面?
How can I set $(TargetDir)
correctly in Team Build context?
推荐答案
我不明白其中$(OutputPath)是由Visual Studio定义。你在你的项目尝试$(TARGETDIR)W /在你的项目?然后你可以从你的大会宣言中的T4文件中删除$(TARGETDIR)\。
I don't see where $(OutputPath) is defined by visual studio. did you try $(TargetDir) in your item w/in your project? Then you can remove the $(TargetDir)\ from your Assembly declaration in the T4 file.
我刚刚通过的可能性,以获得类似的工作摆工作,将在今天或明天做一个博客帖子。
I just worked through a slew of possibilities to get something similar to work, will be doing a blog post today or tomorrow.
所以:
<ItemGroup>
<T4ReferencePath Include="$(TargetDir)" />
</ItemGroup>
在你的csproj,以及
in your csproj, and
<#@ assembly name="MyDependency.dll" #>
在你的T4文件
这篇关于构建过程中T4 code一代,自定义程序集引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!