We've just switched our main project from Visual Studio 20开发者_如何转开发08 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?
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.
精彩评论