T4 CleanUpBehavior directive
This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, use the version selector at the top left. We recommend upgrading to Visual Studio 2019. Download it here
To delete the appDomain after processing a text template, include the following line:
<#@ CleanupBehavior processor="T4VSHost" CleanupAfterProcessingtemplate="true" #>
Text templates are processed in an appDomain that is separate from the host process. In most cases, when one text template has been processed, the appdomain is used again to process the next template. But if you specify CleanupBehavior, the appDomain is deleted and the next template will be processed in a new appDomain.
This slows text processing, but can be useful to make sure that resources are disposed.
This directive works only in the Visual Studio host.