【问题标题】:How do I fix missing type/namespace errors in my Entity Framework 4.1 model template?如何修复 Entity Framework 4.1 模型模板中缺少的类型/命名空间错误?
【发布时间】:2011-09-21 12:11:12
【问题描述】:

我有一个 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'...

我该如何解决这个问题?

【问题讨论】:

    标签: visual-studio-2010 entity-framework code-generation compiler-errors t4


    【解决方案1】:

    事实证明,基于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>
    

    解决方法是手动将.csproj文件中的节点改为None。改变它 通过 .tt 文件的 Visual Studio 属性编辑器返回 不起作用。 最后,禁用扩展可以防止这种情况再次发生。

    【讨论】:

      【解决方案2】:

      只需在.tt 文件的开头添加所需的程序集;像这样:

      <#@ template language="C#" debug="false" hostspecific="true"#>
      <#@ assembly name="System.Data.Entity" #>
      <#@ assembly name="System.Data.Entity.Design" #>
      ...
      

      【讨论】:

        猜你喜欢
        • 2020-06-27
        • 2016-01-31
        • 1970-01-01
        • 2019-06-15
        • 2015-10-06
        • 2017-12-08
        • 2015-12-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多