I have a T4 template for a class set up with TextTemplatingFileGenerator Custom Tool in Visual Studio:
<#@ template language=\"C#v3.5\" hostspecific=\"Tru
Here is what you can do with T4 Toolbox:
<#@ template language="C#v3.5" hostspecific="True" debug="True" #>
<#@ include file="T4Toolbox.tt" #>
<#
var namespaceName = TransformationContext.DefaultNamespace;
#>
DefaultNamespace property of TransformationContext class returns a string with namespace based on the root namespace of your project and the location of your .tt file in it (i.e. it treats folders as namespaces). This way you don't have to specify Custom Tool Namespace property for every instance of your .tt file.
If you prefer to use the Custom Tool Namespace property, you can pass Host.TemplateFile to the GetCustomToolNamespace method posted by @sixlettervariables.