Scaffold DB error

.net asp.net c# entity-framework-core

Question

I have a .NET Core 2.0 solution with two projects. One project is a SQL Server database project. The other project is a .NET Core 2.0 console app project.

In the console project I have been running the scaffold command (shown below) in the PMC without any issues for about a month.

Scaffold-DbContext -Connection "Server=.\SQL2017;Database=RemodelDB;Trusted_Connection=True;" -Provider Microsoft.EntityFrameworkCore.SqlServer -OutputDir Admin\Models -Context "RemodelAdminDbContext"

Today all of sudden this command has broken and now I'm getting the error below.

Startup project '' has an active platform of ''. Select a different platform and try again.

I have done several Google searches for this error message and have read most of the posts on the GIT HUB issues posted on the .NET Core GIT project. None of those solutions and ideas have worked in my case.

Here is what I have tried so far:

1) Created new .NET Core 2.0 Web app and then added the relevant EF Core NuGet packages

2) I have tried wrapping the connection string in single quotes.

3) I have added the EFCore.SQLServer.Design NuGet package

4) I updated all of my EF Core packages to the latest versions.

Please note, that both of my projects build without any errors.

None of the above have resolved my issue. Any help would be much appreciated!

April 23, 2018 Update: It happened again today! I had not worked on this solution/project for a few weeks. Today I created a new table for my app and then tried to scaffold the POCO class and the error appeared!

Here is the complete text shown in the 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.

1
2
4/24/2018 5:03:15 AM

Popular Answer

Had this very same error after having done some updating, including netcore 2.1. It occurred when trying to add a migration to an EfCore project. Not sure however which update caused the problem.

Solution

Since the error indicates something is wrong with the projects platform, I opened the project properties on the Build tab, selected a different "Platform target", saved, then put the platform target back to it's original value (Any CPU) then save again.

Allthough a bit puzzling, that fixed it for me. So maybe this will work for you too and keeps from pulling out more hair :).

1
12/27/2018 3:40:54 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow