Visual Studio 2010 升级后生成的(通过 T4 模板)dll 运行时不兼容
我们刚刚将我们的主项目从 Visual Studio 2008 切换到 2010。我希望一切都会像我之前转换的其他项目一样顺利,但这个项目并非如此...
该项目有一个 T4它使用正则表达式读取 xml 文件并将其编译为 dll(使用 Regex.CompileToAssembly),该模板包含在我们的解决方案中。转换解决方案后,生成的 dll 将 4.0 作为目标,因此无法从我们的 3.5(2.0 运行时)项目中引用它。
我尝试过但没有成功:
<#@ template language="C#v3.5" hostspecific="true" #>
<#@ assembly name="System.Core, Version=3.5.0.0" #>
有什么想法吗?
We've just switched our main project from Visual Studio 2008 to 2010. I was hoping that everything would be smooth as with every other I've converted before but it wasn't the case with this one...
The project has a T4 template that reads an xml file with regular expressions and compiles them to a dll (with Regex.CompileToAssembly) that is included in our solution. After converting the solution the generated dll has 4.0 as target so it can't be referenced from our 3.5 (2.0 runtime) project.
I've tried this with no success :
<#@ template language="C#v3.5" hostspecific="true" #>
<#@ assembly name="System.Core, Version=3.5.0.0" #>
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您实际上只是将 T4 用作一种脚本运行程序,而不是从模板系统本身生成输出。相反,您将显式生成输出作为程序集。
VS2010 中的 T4 始终使用 4.0 运行时/clr 进行编译,并且似乎没有办法要求 RegEx.Compile 方法吐出 2.0 程序集。
即使您将 RegEx.Compile 移动到针对 2.0 目标构建的帮助程序库中,那么当加载到 4.0 CLR 中时,它也会统一到 4.0 版本。
相反,您需要一种将 2.0 CLR 放入内存的方法,迄今为止最简单的方法是将模板代码移至其自己的 exe 中。
然后,您可以从自定义项目预构建规则中调用此 exe。
It sounds like you're really using T4 just as a sort of script runner rather than to generate output from the templating system itself. Instead you're explicitly generating the output as an assembly.
T4 in VS2010 always uses the 4.0 runtime/clr to compile, and there doesn't appear to be a way to ask the RegEx.Compile method to spit out a 2.0 assembly.
Even if you move the RegEx.Compile into a helper library built to target 2.0, then when loaded into the 4.0 CLR, it will just get unified up to the 4.0 version.
Instead, you need a way to get the 2.0 CLR into memory, for which by far the easiest way is to move your template code into its own exe.
You could then call this exe from a custom project pre-build rule.