MvcBuildViews true 与 ASP.NET MVC 2 中的实体框架

发布于 2024-08-30 21:10:33 字数 322 浏览 3 评论 0原文

在 VS 2010 中,如果您使用的是实体框架,则更改 MVC2 项目的 .csproj 文件中的 true 会导致错误。

无法加载类型“System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider”。 C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config 129

我想在调试时构建视图,并且我还希望我的项目能够编译!

In VS 2010, changing <MvcBuildViews>true</MvcBuildViews> in a MVC2 project's .csproj file causes an error if you are using Entity Framework.

Could not load type 'System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider'. C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config 129

I want to build views while I'm debugging, and I also want my project to compile!

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

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

发布评论

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

评论(6

心碎的声音 2024-09-06 21:10:33

您可以通过将以下元素添加到 web.config 文件来解决此 MVC 编译问题:

<add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

这将告诉编译器在哪里可以找到缺少的类型。

You can resolve this MVC compile issue by adding the following element to your web.config file:

<add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

This will tell the compiler where to find that missing type.

几味少女 2024-09-06 21:10:33

我也遇到了这个问题,并发现我创建了一些实体文件(edmx 等)但已删除它们。

这个问题是在我创建这些文件后才开始发生的。在检查应用程序文件夹时,我发现 Visual Studio 实际上并没有将它们从驱动器中“删除”,它只是将它们从项目中“删除”了。因此,当项目被编译时,它看到了这个 edmx 文件并决定将其包含在内。因此出现错误。

简单修复 - 从驱动器上永久删除实体文件!

i had this problem too, and figured out that i had created some entity files (edmx and the like) but had deleted them.

this problem only started happening after i had created these files. on inspection of the application folders, i found that visual studio hadn't actually 'deleted' them off the drive, it had just 'deleted' them out of the project. therefore, when the project was being compiled, it saw this edmx file and decided it would include it. hence the error.

easy fix - permanently delete the entity files off the drive!

冷心人i 2024-09-06 21:10:33

或者,您可以删除构建提供程序。

<system.web>
  <compilation debug="true" targetFramework="4.0">
    <buildProviders>
      <remove extension=".edmx"/>
    </buildProviders>
  </compilation>
</system.web>

Alternately you can remove the build provider.

<system.web>
  <compilation debug="true" targetFramework="4.0">
    <buildProviders>
      <remove extension=".edmx"/>
    </buildProviders>
  </compilation>
</system.web>
梦断已成空 2024-09-06 21:10:33

这是一个完整的 web.config 示例

<configuration>
<system.web>
    <customErrors mode="Off"/>
        <compilation debug="true" targetFramework="4.0">
 <assemblies>
    <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />       
    <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </assemblies>
</compilation>
</system.web>
</configuration>

This is an complete example web.config

<configuration>
<system.web>
    <customErrors mode="Off"/>
        <compilation debug="true" targetFramework="4.0">
 <assemblies>
    <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />       
    <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </assemblies>
</compilation>
</system.web>
</configuration>
不及他 2024-09-06 21:10:33

我在设置 MvcBuildViews="true" 时遇到了类似的错误,这与由于构建临时文件而发现多个 web.configs 的构建有关,并且根本不喜欢它。

这是一个完全不同的错误,但我偷偷怀疑它们可能相关...

您可以找到我的原始问题 此处,然后概述解决方案此处

该解决方案基本上让您更改构建的输出路径...因此您需要将 添加到网站的 csproj 文件中。

例如

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    ...BLAH...
    <BaseIntermediateOutputPath>..\TempBuildOutput</BaseIntermediateOutputPath>
  </PropertyGroup>
  ...A WHOLE LOTTA BLAH...
</Project>

HTH,
查尔斯

I had a similar error when setting MvcBuildViews="true" which had to do with the build finding multiple web.configs due to build temp files and simply not liking it.

It's a totally different error, but I have a sneaky suspicion that they could be related...

You can find the original question I had here and then the solution outlined here.

The solution basically gets you to change where the output path is for you builds... so you need to add <BaseIntermediateOutputPath> to your website's csproj file.

E.g.

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    ...BLAH...
    <BaseIntermediateOutputPath>..\TempBuildOutput</BaseIntermediateOutputPath>
  </PropertyGroup>
  ...A WHOLE LOTTA BLAH...
</Project>

HTHs,
Charles

z祗昰~ 2024-09-06 21:10:33

没有足够的代表来添加评论。想要提及的是,您需要将“System.Data.Entity.Design”程序集引用添加到根 Web.config。我无意中尝试将其添加到我的 Views 目录中的 Web.config 中。小心这个陷阱。

Not enough rep to add a comment. Wanted to mention that you need to add the 'System.Data.Entity.Design' assembly reference to the root Web.config. I was inadvertently trying to add it to a Web.config in my Views directory. Watch out for this pitfall.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文