我有一个包含两个项目的 .NET Core 2.0 解决方案。一个项目是 SQL Server 数据库项目。另一个项目是 .NET Core 2.0 控制台应用程序项目。
在控制台项目中,我已经在 PMC 中运行脚手架命令(如下所示)大约一个月没有任何问题。
Scaffold-DbContext -Connection "Server=.\SQL2017;Database=RemodelDB;Trusted_Connection=True;" -Provider Microsoft.EntityFrameworkCore.SqlServer -OutputDir Admin\Models -Context "RemodelAdminDbContext"
今天突然这个命令坏了,现在我收到下面的错误。
Startup project '' has an active platform of ''. Select a different platform and try again.
我在 Google 上多次搜索此错误消息,并阅读了 .NET Core GIT 项目上发布的关于 GIT HUB 问题的大部分帖子。这些解决方案和想法都不适用于我的案例。
到目前为止,这是我尝试过的:
1) 创建新的 .NET Core 2.0 Web 应用程序,然后添加相关的 EF Core NuGet 包
2) 我试过将连接字符串用单引号引起来。
3) 我添加了 EFCore.SQLServer.Design NuGet 包
4) 我将我的所有 EF Core 包都更新到了最新版本。
请注意,我的两个项目都没有出现任何错误。
以上都没有解决我的问题。任何帮助将不胜感激!
2018 年 4 月 23 日更新: 今天又发生了!我已经有几周没有研究这个解决方案/项目了。今天我为我的应用程序创建了一个新表,然后尝试搭建 POCO 类的脚手架,但出现了错误!
这是 PMC 中显示的完整文本:
PM> Scaffold-DbContext -Connection "Server=.\SQL2017;Database=RemodelAppDB;Trusted_Connection=True;" -Provider Microsoft.EntityFrameworkCore.SqlServer -OutputDir Admin\Models -Context "RemodelAdminDbContext" Startup project '' has an active platform of ''. Select a different platform and try again. PM> Scaffold-DbContext -Connection "Server=.\SQL2017;Database=RemodelAppDB;Trusted_Connection=True;" -Provider Microsoft.EntityFrameworkCore.SqlServer -OutputDir Admin\Models -Context "RemodelAdminDbContext" -Force -Verbose Using project 'Remodel.POCOGenerator'. Using startup project ''. Build started... Build succeeded. Startup project '' has an active platform of ''. Select a different platform and try again. PM> Scaffold-DbContext -Connection "Server=.\SQL2017;Database=RemodelAppDB;Trusted_Connection=True;" -Provider Microsoft.EntityFrameworkCore.SqlServer -OutputDir Admin\Models -Context "RemodelAdminDbContext" -Force -Verbose Using project 'Remodel.POCOGenerator'. Using startup project ''. Build started... Build succeeded. Startup project '' has an active platform of ''. Select a different platform and try again.
最佳答案
在完成一些更新后出现了同样的错误,包括 netcore 2.1。 它发生在尝试向 EfCore 项目添加迁移时。但是不确定是哪个更新导致了问题。
解决方案
由于错误表明项目平台有问题,我在“构建”选项卡上打开项目属性,选择不同的“平台目标”,保存,然后将平台目标恢复为原始值(任何 CPU)然后再次保存。
虽然有点令人费解,但这对我来说已经解决了。所以也许这对你也有用,并且不会拔出更多的头发 :)。
关于c# - 脚手架数据库错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49641840/