MvcBuildViews true with Entity Framework in ASP.NET MVC 2

不打扰是莪最后的温柔 提交于 2019-11-26 20:19:54

问题


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!


回答1:


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.




回答2:


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!




回答3:


Alternately you can remove the build provider.

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



回答4:


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>



回答5:


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




回答6:


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.



来源:https://stackoverflow.com/questions/2762256/mvcbuildviews-true-with-entity-framework-in-asp-net-mvc-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!