【发布时间】:2016-05-13 06:50:54
【问题描述】:
总结: 在 Visual Studio 2015(更新 1)中创建新的 Web 项目时, 我无法使用与实体框架相关的控制器的脚手架工具。
VS2013 Update 5 出现同样的问题
它返回以下消息:
运行所选代码生成器时出错:
获取类型“failtest.Models.TestModelClass”时出错。
尝试重建项目。
我试图重建它,但仍然没有。
有人知道我为什么会得到这个吗? 我实际上重新安装了我的 Windows 10 系统,看看这是否可以解决这个错误。 - 现在,那个蜜蜂说,无论如何它都需要一些严厉的爱,所以我认为它是时候了 - 也许它崩溃了,因为我在过去的时间里尝试了大量的节点东西,以及权限错误。 但是在我重新安装它之前和之后都发生了错误。 (完整的鞭子)
这是 Visual Studio 2015 Professional 的全新安装 - 基本上尚未向系统添加任何其他内容。
当我第一次开始这篇文章时,我为我的屏幕截图创建了一个空白项目,只是为了显示整个过程(如下) - 我认为我正在失去理智。
起初,testproject 突然起作用了,所以我创建了第二个项目来再次测试。 然后它因同样的错误而失败。 所以只是为了确认,我删除了第一个工作的项目,并使用与突然工作的项目完全相同的名称和文件位置再次设置它(在删除所有文件夹和现有项目文件之后) - 现在它再次失败。
如何重现:
- 创建一个新的“Azure Api App”项目 - 将所有设置保留为默认设置(任何项目类型实际上都会产生相同的结果)
- 创建一个新模型
构建您的项目(Microsoft 的一篇文章中提到需要使用脚手架)
通过右键单击“Controllers”文件夹并选择New -> Controller 添加新控制器 - 选择“Web Api 2.0 controller with actions, using Entity Framework强>"
- 填写信息,因为这是一个新项目,我们没有上下文 - 所以单击 + 图标并创建一个新项目。
- 产生错误
编辑:
Packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="8.0.2" targetFramework="net452" />
<package id="Swashbuckle" version="5.3.1" targetFramework="net452" />
<package id="Swashbuckle.Core" version="5.3.1" targetFramework="net452" />
<package id="System.IdentityModel.Tokens.Jwt" version="4.0.2.206221351" targetFramework="net452" />
<package id="WebActivatorEx" version="2.1.0" targetFramework="net452" />
</packages>
Web.Config:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301879
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings></appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
编辑 2: 我怀疑这是一个 EntityFramework 问题,因为脚手架适用于不包括 EntityFramework 的所有内容。
已经测试过
- 在调试和发布配置之间切换
- 更新了所有的包和插件
- 验证解决方案文件和项目 XML
- 已验证的 Web.config
- 已删除 Bin / Debug 文件夹
- 具有不同项目类型的新项目
描述相同错误的问题 - 已全部测试
- Scaffolding/Auto code generator completely broken?
- There was an error running the selected code generator...
- How do i add a controller to asp.net MVC....
- External: There was an error running the selected code generator
- External: VS2013 scaffolding error
- Scaffolding controller doesn't work with visual studio 2013 update 2
我还在 aspnet Github 问题跟踪器上创建了一个关于此的问题。 https://github.com/aspnet/Tooling/issues/411
并通过 Visual Studio 中的内部反馈系统向 Microsoft 报告。
【问题讨论】:
-
尝试将配置更改为“发布”/“调试”,重新构建,然后重试
-
@RaraituL:尝试了您的解决方案,但没有任何成功结果。
-
我要做的第一件事是确保我正在运行最新版本的 VS 的 Azure 插件。这种情况每隔几个月就会发生变化,运行过时的版本很容易。
-
@MartijnK - 所有插件都是最新的。昨天下载了 VS 和 Azure SDK 的最新更新。我还将项目中的所有 nuget 包更新为最新版本(原始问题中列出的包) - 没有任何效果。
-
我也得到了这个,即使对于一个常规的绿色 WebApi 项目也是如此。我想知道这是否与最近的更新有关?
标签: c# entity-framework visual-studio asp.net-web-api