I have a T4 template that can output either optimized content or standard content based on a flag. Currently I'm manually changing the flag based on my needs.
What I'd love to do is set the flag based on the Configuration of the Solution in Visual Studio. If set to build in Debug mode, I would output standard content. If set to build in Release mode, I would optimize the content instead. I found another T4 question that looks promising: T4 Text Template - Is it possible to get compilation symbols from host?
However, in my case I would want to do something like the following:
<#@ template language="C#" hostspecific="True"
compilerOptions="/d:$(ConfigurationName)" #>
Since I can use $(SolutionDir) in an assembly directive:
<#@ assembly name="$(SolutionDir)\myreference.dll" #>
I would think the /d:$(ConfigurationName) would get me where I needed to go, and then I could do the following to set my flag:
<#
#if Debug
optimize = false;
#else
optimize = true;
#endif
#>
Alas, this doesn't seem to work. I've also attempted using:
Host.ResolveParameterValue("-", "-", "ConfigurationName");
Also to no avail. Any ideas?