tags:

views:

29

answers:

1

When creating a T4 template in VB.NET, how do you specify Option Explicit, Option Strict, and Option Infer settings? There's some sort of <#@ #> tag for doing this, but I can't find it.

+2  A: 

If you're using Visual Studio 2010, the <#@ template #> directive has a new 'compilerOptions' parameter. This allows options to be passed directly to the codedom compiler. For example, for the VB compiler, /optionstrict+- /optioninfer+- /optionexplicit+-.

Hope this helps.

GarethJ
That's really handy, thanks. Any chance there's something similar for Pre-processed templates? The `compilerOptions` attribute only seems to do any good on the old-style templates.
mattmc3
The preprocessed templates don't get compiled within T4, so we don't push anything. We assuming that you'll set this on a per-project level with project compile settings for the project that the template output is built in.That unfortunately doesn't give you a per-template control. We don't currently have any plans to provide that level of control.
GarethJ
GarethJ - That is a bummer. Especially since with the new dynamic features in the 4.0 framework, you have to set Option Strict Off to use things like ExpandoObject. Obviously, you wouldn't want to do that at a project level, but at a template level it might be acceptable. Anyway, thanks for the help.
mattmc3
Yes, I can see that it would be useful to have more granular control, but there's no way I can think of to hack it in VS2010 unfortunately. Can I suggest that you log a bug in Connect to ask for the fine grained control. http://connect.microsoft.com/VisualStudio
GarethJ