如何修复 Entity Framework 4.1 模型模板中缺失的类型/命名空间错误?

发布于 2024-11-16 21:58:21 字数 629 浏览 7 评论 0原文

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

我该如何修复此问题?

I have a T4 template to generate C# classes for the entities backing my .edmx model. The template starts with this header:

<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ include file="EF.Utility.CS.ttinclude"#>
<#@ output extension=".cs"#>

Attempting to build the project results in these errors

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'...

How can I fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心安伴我暖 2024-11-23 21:58:21

事实证明,基于 VS扩展性线程,问题的原因是
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。改变它
通过 Visual Studio 属性编辑器返回 .tt 文件不起作用
最后,禁用扩展可以防止这种情况再次发生。

It turns out than, based on a VS Extensibility thread, the reason for the problem was
the Clarius Visual T4 extension. It reset this node in the .csproj
file to

<Compile Include="SomeModel.tt">
  <Generator>TextTemplatingFileGenerator</Generator>
  <LastGenOutput>SomeModel.cs</LastGenOutput>
</Compile>

from

<None Include="SomeModel.tt">
  <Generator>TextTemplatingFileGenerator</Generator>
  <LastGenOutput>SomeModel.cs</LastGenOutput>
</None>

The solution is to manually change the node to None in the .csproj file. Changing it
back via the Visual Studio properties editor for the .tt file does not work.
Finally, disabling the extension prevents this from happening again.

海风掠过北极光 2024-11-23 21:58:21

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

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

Just simply add needed assemblies at the beginning of your .tt file; like this:

<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ assembly name="System.Data.Entity" #>
<#@ assembly name="System.Data.Entity.Design" #>
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文