Visual Studio 2015,T4 模板:汇编指令不使用卷影复制

Visual Studio 2015, T4 template: Assembly directive does not use Shadow Copying

重建解决方案时,我收到错误消息:-

Error       Unable to copy file "obj\Debug\TargetTest.dll" to "bin\Debug\TargetTest.dll". The process cannot access the file 'bin\Debug\TargetTest.dll' because it is being used by another process.    

当我删除汇编指令时,解决方案重建:-

<#@ template debug="true" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="C:\Code\T4Template\bin\Debug\TargetTest.dll" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Reflection" #>
<#@ output extension=".cs" #>

如何解决这个问题?我想这与 visual studio 中的影子复制配置有关,但我找不到它。

T4设计时模板在visual studio的相同进程下在不同的App域中处理。重建解决方案时 Visual Studio 尝试替换引用的 DLL,但无法替换它,因为它仍在使用中。

我通过删除处理 T4 模板的 AppDomain 解决了这个问题。参见 msdn