Is there an acceptable way to generate the HTML/ASP portion of an ASPX page (not the code behind) based on the configuration selected in Visual Studio? For example, I want to display different header graphics on my Development landing page (a header that notifies the user they are looking at Development), and different graphic for Production build.
I use SlowChetah for transforming my config files, so my first thought was to use something like that for ASPX pages, but I haven't found any information regarding that sort of functionality or feature.
This could be achieved using the T4 text templates in combination with the DTE object, as described at the bottom of Accessing Visual Studio or other Hosts from a T4 Text Template, to get the current build configuration and generate the required portion of the 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>
<#
}
#>
The output of the template could then be included in the actual ASPX page, e.g. via a Literal control, or as a user control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With