Recently I had gone through the below error while running entity framework core migrations with .Net Standard. This might help you in case if you face the similar issue,
Startup project ‘Core.Migrations’ targets framework ‘.NETStandard’. There is no runtime associated with this framework,
and projects targeting it cannot be executed directly.
To use the Entity Framework Core Package Manager Console Tools with this project,
add an executable project targeting .NET Framework or .NET Core that references this project,
and set it as the startup project; or, update this project to cross-target .NET Framework or .NET Core.
For more information on using the EF Core Tools with .NET Standard projects, see https://go.microsoft.com/fwlink/?linkid=2034705
The error message means that there is no such thing as an executable .NET Standard project. There is no run-time for it because it is simply a type-forwarding mechanism for multiple different runtimes.
We have two solutions for this,
- Create a new empty .Net Core console app or web app and set that as Startup Project or If you have an app (either of them) created already in the same solution then set that project as Startup Project. This will solve the issue.
- or You can do the below as well in the csproj file,
Replace<PropertyGroup> <TargetFramework>netstandard20</TargetFramework> </PropertyGroup>
with<PropertyGroup> <TargetFrameworks>netcoreapp2.0;netstandard2.0</TargetFrameworks> </PropertyGroup>
(Notice that the attribute name is now plural and there is a semi-colon between the two.)
But, there’s one more secret which is not in the documentation,
For .NET Standard 2.0 (and EF Core 2.0), you also need to add the following to csproj.<PropertyGroup> <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> </PropertyGroup>
Now set the DbContext project as the Startup project and make sure that the package manager console (or command line) are pointing to the same project, your migration commands will work.
The solution is to pick an executable platform for your application to run on. You can reference as many .NET Standard libraries as you like from your executable (as long as they are compatible with your run-time), but the executable itself cannot be run on .NET Standard. It must target a platform such as .NET Framework or .NET Core in order to execute.
In other words, in order to use a command to scaffold your database, you have to target a runtime. So you will either need to run this command while targeting your main executable project, or add a new executable project to your solution to run it on.
Hope this helps you!
Enjoy the reading..!
P.S: thanks to stackoverflow (copy&pasted few above content randomly)