Is it possible to use conditional compilation directives?

Feb 23, 2009 at 10:37 PM
Hi Oleg,
Its a bit of a cheek to ask you over on this forum, but...

Can I do this:

<#
#if (DEBUG)
    PropertyFile = "file://properties-dev.config";
#else
    PropertyFile = "file://properties-live.config";
#endif
#>

This does not seem to work - the DEBUG constant is never detected.

Thanks in advance
Christian


Coordinator
Feb 25, 2009 at 12:18 AM
Edited Feb 25, 2009 at 12:14 PM
Christian,

I assume you have tried using <#@ template debug="true" #> with this and it didn't work.

I haven't found a way to make conditional compilation work in T4 templates. C# only permits #define directive in the beginning of a source file, so no matter where you put it in a .tt file, it's always wrong. I don't thinks it would be possible with a custom directive processor either.

You may be able to achieve a similar result with a regular if statement - check TransformationContext.Project.ConfigurationManageer.ActiveConfiguration property.

Oleg
Feb 25, 2009 at 1:03 PM
Thanks Oleg for the confirmation - I thought it was me just not doing something correctly.
>I assume you have tried using <#@ template debug="true" #> with this.
I tried it with and without specifying the debug attribute but it had no effect. Even if it did work, it still wouldn't be a good solution as I needed to use the Project Configuration to define the DEBUG.
Thanks as always.
C


From: olegsych <notifications@codeplex.com>
To: christian.crowhurst@btinternet.com
Sent: Wednesday, 25 February, 2009 1:19:34 AM
Subject: Re: Is it possible to use conditional compilation directives? [t4toolbox:48301]

From: olegsych

Christian,r

I assume you have tried using <#@ template debug="true" #> with this.

I haven't found a way to make conditional compilation work in T4 templates. C# only permits #define directive in the beginning of a source file, so no matter where you put it in a .tt file, it's always wrong. I don't thinks it would be possible with a custom directive processor either.

You may be able to achieve a similar result with a regular if statement - check TransformationContext.Project.ConfigurationManageer.ActiveConfiguration property.

Oleg