是否有一种可接受的方法来根据在Visual Studio中选择的配置生成ASPX页面的HTML / ASP部分(而不是后面的代码)?例如,我想在我的开发登录页面上显示不同的标题图形(通知用户他们正在查看开发的标题),以及生成构建的不同图形。
我使用SlowChetah来转换我的配置文件,所以我首先想到的是为ASPX页面使用类似的东西,但我没有找到任何有关这种功能或功能的信息。
答案 0 :(得分:1)
这可以使用T4 text templates与DTE对象结合实现,如Accessing Visual Studio or other Hosts from a T4 Text Template底部所述,以获取当前构建配置并生成ASPX的所需部分:
<#@ template hostspecific="true" #>
<#@ output extension=".aspx" #>
<#@ assembly name="EnvDTE" #>
<#@ import namespace="EnvDTE" #>
<#
// Get the environment object
IServiceProvider serviceProvider = (IServiceProvider)Host;
DTE dte = serviceProvider.GetService(typeof(DTE)) as DTE;
// Get the active build configuration object
var activeConfiguration = dte.Solution.SolutionBuild.ActiveConfiguration;
// Generate customized ASPX content
if (activeConfiguration.Name == "Debug")
{
#>
<h1>Debug</h1>
<#
}
else
{
#>
<h1>Release</h1>
<#
}
#>
然后,模板的输出可以包含在实际的ASPX页面中,例如,通过Literal
控件或用户控件。