This looks like a T4 engine bug or am I doing something wrong
I have a t4 template that generates c++ code I need to dynamically specify an include file.
I have removed all of the logic of my code just to illustrate the error.
The following won't compile. Error 2 An unexpected start or end tag was found within a block. Make sure that you did not mis-type a start or end tag
void foo()
{
string bob = "";
#>
#include "..\..\SomeDir\<#=bob #>"
<#+
}
#>
If you add a space to the #include line开发者_C百科 it solves the issue.
void foo()
{
string bob = "";
#>
#include "..\..\SomeDir\ <#=bob #>"
<#+
}
#>
is this a bug or is there some syntax i'm missing to handle a \ followed by a <
The backslash is escaping the open tag for the <#= bob #> expression block, so you'll need to escape the backslash itself with another backslash.
#include "..\..\SomeDir\\<#=bob #>"
should do the trick.
As GarethJ mentioned the double backlash should work. I tried the following T4 template in VS2010 SP1 and it seems to work as expected.
<#@ output extension=".hpp" #>
<#
foo ();
#>
// Test
<#+
void foo ()
{
var bob = "XYZ";
#>
#include "..\\<#=bob#>.h
<#+
}
#>
In this particular a workaround could be to use forward slashes in paths (ie '/') instead of back slashes (ie '\')
精彩评论