I have a T4 template for a class set up with TextTemplatingFileGenerator Custom Tool in Visual Studio:
<#@ template language=\"C#v3.5\" hostspecific=\"Tru
If you're using Visual Studio 2010, you can retrieve the namespace by checking the CallContext's "NamespaceHint" property.
System.Runtime.Remoting.Messaging.CallContext.LogicalGetData("NamespaceHint");