使用TransformOnBuild时不能引用依赖组件在T4模板 [英] Cannot reference dependency assemblies in T4 template when using TransformOnBuild

查看:371
本文介绍了使用TransformOnBuild时不能引用依赖组件在T4模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试使用T4与Visual Studio 2010(SP1)打造的脚本对于那些基于我们的一些现有的C#类的另一种语言。我希望以下内容:

We're trying to use T4 with Visual Studio 2010 (SP1) to build scripts for another language that are based upon some of our existing C# classes. I'm hoping for the following:


  1. 模板需要加载我们现有的装配,并从该程序集的命名空间使用对象
  2. 的转变需要每个开发机器上运行的每个建设和构建服务器,而无需任何额外的安装。

  3. (1)和(2)需要工作一起

(1)相当简单:

<#@ assembly name="$(TargetDir)RequiredProject.dll" #>
<#@ import namespace="RequiredProject.RequiredNamespace" #>



使用 $(TARGETDIR)宏允许我引用的DLL与一个完全合格的UNC路径(每个指令的这里找到)。

Using the $(TargetDir) macro allowed me to reference the dll with a fully qualified UNC path (per the instructions found here).

( 2)是一个有点迂回,但我想我已经得到了它解决:我安装的所需的文本转换的SDK 一个不同的机器上,并复制所需的.targets和.dll文件到一个文件夹在我的解决方案,然后更新了我的.csproj文件以引用本地.targets文件。

(2) is a bit roundabout, but I think I've got it solved: I installed the required text transformation SDKs on a different machine and copied the required .targets and .dlls into a folder in my solution and then updated my .csproj file to reference the local .targets file.

(3)是我遇到的问题。这似乎是< TransformOnBuild>真< / TransformOnBuild>在一个引用的程序集需要改造之前要建属性没有很好地发挥。每次我启用引用的程序集的构建变换,我得到以下错误:

(3) is where I run into problems. It seems like the <TransformOnBuild>true</TransformOnBuild> property doesn't play nicely when a referenced assembly needs to be built prior to the transformation. Everytime I enable transform on build with referenced assemblies, I get the following error:

Compiling transformation: Metadata file '$(TargetDir)RequiredProject.dll' could not be found.



不过,我使用,我用(1)引用相同的汇编指令部件。事实上,直接到.TT模板并保存它仍然会产生预期的输出 - 它只是没有在建的步骤工作。我做得不对,或者是有没有办法保证的它们所依赖的组件内置发生模板转换? (或者更简单地说,发生模板转换的最后?)

However, I'm using the same assembly instruction that I was using in (1) to reference the assembly. In fact, going to the .tt template directly and saving it still produces the expected output -- it just doesn't work during the "build" step. Am I doing something wrong, or is there a way to ensure that the template transformations occur after the assemblies they depend on are built? (Or, more simply, that template transformations occur last?)

推荐答案

不幸的是,MSBuild的T4主机还不支持在程序集名称嵌入的宏或MSBuild的变量。

Unfortunately, the msbuild T4 host doesn't yet support embedded macro or msbuild variables in assembly names.

但是,它支持Windows环境变量%富%,所以尽管这意味着一些机-level设置,你可以得到的东西,在IDE工作跨越和构建时间变换。

However, it does support Windows environment variables "%foo%", so although it means some machine-level setup, you can get something that works across in-IDE and build time transforms.

这篇关于使用TransformOnBuild时不能引用依赖组件在T4模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆