MvcBuildViews true with Entity Framework in ASP.NET MVC 2

前端 未结 6 826
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 12:51

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

<
相关标签:
6条回答
  • 2020-12-05 13:29

    Alternately you can remove the build provider.

    <system.web>
      <compilation debug="true" targetFramework="4.0">
        <buildProviders>
          <remove extension=".edmx"/>
        </buildProviders>
      </compilation>
    </system.web>
    
    0 讨论(0)
  • 2020-12-05 13:42

    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.

    0 讨论(0)
  • 2020-12-05 13:44

    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>
    
    0 讨论(0)
  • 2020-12-05 13:49

    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

    0 讨论(0)
  • 2020-12-05 13:52

    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.

    0 讨论(0)
  • 2020-12-05 13:53

    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!

    0 讨论(0)
提交回复
热议问题