Visual Studio 2010存在.Net T4问题-Host.LoadIncludeText不解释代码

Visual Studio 2010存在.Net T4问题-Host.LoadIncludeText不解释代码,.net,visual-studio-2010,t4,.net,Visual Studio 2010,T4,我们有app.config文件,可部署到8个不同的环境中,例如Dev、Local、Test、UAT、Prod等。为了便于更改,每个顶层都有。tt如下所示: e、 g app.dev.tt CommonTemplate.t包括: ... MasterConfig.t包含如下内容: <# EnvironmentName = @"Dev"; #> <#@ include file="CommonTemplate.ttinclude" #> <#@ te

我们有app.config文件,可部署到8个不同的环境中,例如Dev、Local、Test、UAT、Prod等。为了便于更改,每个顶层都有。tt如下所示:

e、 g

app.dev.tt

CommonTemplate.t包括:

...
MasterConfig.t包含如下内容:

<#
    EnvironmentName = @"Dev";
#>
<#@ include file="CommonTemplate.ttinclude" #>
<#@ template language="C#" hostspecific="True" #>
<#@ output extension="config" #>
<#@ include file="..\MasterConfig\MasterConfig.ttinclude" #>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   ...
</configuration>
   <#
        string hostPath = this.Host.ResolvePath("..\MasterConfig");
        string EnvironmentIncludePath = string.Format(@"{0}\EnvironmentSettings\{1}.ttinclude", hostPath, EnvironmentName);

        EnvironmentIncludePath = System.IO.Path.GetFullPath(EnvironmentIncludePath);
        string context = null;
        string resolvedName = null;
        Host.LoadIncludeText(EnvironmentIncludePath, out context, out resolvedName);

        public string ServicesMachineName = "";
<#
    ServicesMachineName = "SOMESERVERNAME";
        ... [snip other setting specific stuff stuff]
#>
switch(EnvironmentName.ToUpper().Trim())
    {
        case "DEV":
            #><#@ include file="..\MasterConfig\EnvironmentSettings\Dev.ttinclude" #><#
            break;
        case "LOCAL":
            #><#@ include file="..\MasterConfig\EnvironmentSettings\Local.ttinclude" #><#
            break;
        default:
            throw new Exception("Error the specified Environment Name was not found");
    }