2012-02-01 66 views
3

基于在Visual Studio中选择的配置,是否有一种可接受的方式来生成ASPX页面的HTML/ASP部分(而不是后面的代码)?例如,我想在我的开发着陆页上显示不同的页眉图形(通知用户他们正在查看开发的页眉),以及生成生成的不同图形。ASPX页面的SlowChetah-like转换?

我使用SlowChetah来转换我的配置文件,所以我的第一个想法是使用类似于ASPX页面的东西,但是我还没有找到任何有关该类功能或功能的信息。

回答

1

这可能与DTE对象组合使用T4 text templates来实现,如在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控件,或者作为一个用户控件。