我有一个T4模板,可以为支持.edmx
模型的实体生成C#类。模板以此标头开头:
<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ include file="EF.Utility.CS.ttinclude"#>
<#@ output extension=".cs"#>
尝试构建项目会导致这些错误
error CS0234: The type or namespace name 'Design' does not exist in the namespace 'System.Data.Entity'...
error CS0246: The type or namespace name 'EnvDTE' could not be found (are you missing a using directive...
error CS0234: The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft'...
我该如何解决这个问题?
答案 0 :(得分:4)
事实证明,基于VS Extensibility thread,问题的原因是
Clarius Visual T4扩展。它在.csproj
中重置此节点
归档
<Compile Include="SomeModel.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>SomeModel.cs</LastGenOutput>
</Compile>
这
<None Include="SomeModel.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>SomeModel.cs</LastGenOutput>
</None>
解决方案是手动将节点更改为None
文件中的.csproj
。改变它
通过Visual Studio属性编辑器返回.tt
文件不起作用。
最后,禁用扩展可以防止再次发生这种情况。
答案 1 :(得分:0)
只需在.tt
文件的开头添加所需的程序集即可;像这样:
<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ assembly name="System.Data.Entity" #>
<#@ assembly name="System.Data.Entity.Design" #>
...