6

I'm trying to create a EF 6.4 migration in my solution which has net472 projects and netstandard projects, and I'm getting the following error:

Project 'ESP.Console' targets framework '.NETStandard'. The Entity Framework Package Manager Console Tools don't support this framework.

However, the 'ESP.Console' app doesn't target .NETStandard, it's targetting net472:

  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
    <LangVersion>7.3</LangVersion>
    <OutputType>Exe</OutputType>
  </PropertyGroup>

I have ESP.Console console app set as my startup project, and I have the ESP.Data project as my default project in the Package Manager console.

This is the setup for ESP.Data.csproj:

  <PropertyGroup>
    <TargetFrameworks>netstandard2.1;net472</TargetFrameworks>
    <EmbeddedResourceUseDependentUponConvention>true</EmbeddedResourceUseDependentUponConvention>
  </PropertyGroup>

I need this to target both netstandard and net472 while I am in the process of converting other applications in the solution to run on .net core.

Why am I getting this error? Is there another command like dotnet ef I can use that will work with my EF 6.4 project?

We've used EF migrations on this solution hundreds of times, but since the last time I needed to run a migration we've done two major changes to the solution- converted all the csproj files to use the new format (with PackageReference, etc) and converted the core projects to target either .net standard 2.0 or 2.1 where needed. So I think the issue is related to that.

Attempting to change ESP.Console application to run as netcoreapp3.1 gave the same error.

DLeh
  • 23,806
  • 16
  • 84
  • 128
  • I think "dotnet ef " is for Core only. In VS try "Add-Migration InitialCreate -Namespace Your.Namespace" https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/?tabs=dotnet-core-cli – Greg Jul 02 '20 at 18:16
  • @Greg that's what I thought. In VS I ran this command: add-migration OrderEventMigration -Namespace ESP.Data.Migrations but this gave me the error: Add-Migration : A parameter cannot be found that matches parameter name 'Namespace'. – DLeh Jul 02 '20 at 18:17
  • it should be as simple as add-migration test. Have a look at https://www.entityframeworktutorial.net/code-first/code-based-migration-in-code-first.aspx. I assume you've done enabled migrations? – Greg Jul 02 '20 at 18:24
  • Yup we've used this project for migrations plenty before, and add-migration usually worked. Over the past few months we migrated our solution to use the new csproj format and converted the core librararies to use .net standard instead of just net472. I haven't done a migration in a while and when I tried to today I'm getting this error message – DLeh Jul 02 '20 at 18:35
  • have a look at https://stackoverflow.com/questions/48673987/trying-to-set-up-entity-framework-core-in-net-standard-project - maybe the issue is that the net 472 doesn't have an executable? – Greg Jul 02 '20 at 18:49
  • I showed in the question that it does – DLeh Jul 06 '20 at 13:22

4 Answers4

1

I have found a solution to my problem, though it is a bit messy since I will need to make a temporary change to a csproj file in order to get this to run.

In my case, the ESP.Data (the project housing my DbContext) was targeting both net472 and netstandard2.1, I altered the Data project to remove the netstandard2.1 target framework. It seems there is a bug in VS that is saying that the StartupProject targets NetStandard instead of saying that the Target project does. After I create the migration, I can add the target back again.

I will be moving to .net core compilation soon, and will therefore need that netstandard 2.1 target at some point, so I'm not sure what I'll do when that comes. I may need to preserve a net472 console application to use in the future and continue targeting net472 in my data project after that migration is done in order to continue to create migrations.

DLeh
  • 23,806
  • 16
  • 84
  • 128
0

I had a simular problem.
My problem was, that I was targeting netcoreapp3.1 with my startup project and used Entity Framework 6 tools.
When I switched to EntityFrameworkCore tools it worked.

  • I don't see an "EntityFrameworkCore tools" when I go to Tools > Get Tools and Components > Individual Components. Am I not looking in the right place? VS2022 17.3.3 – Meekohi Sep 14 '22 at 14:47
0

Might be a bug in Visual Studio -- I was seeing this error after I changed the Startup Project to the correct project with my migrations, even though my project uses .NET Framework 4.8.

Tried several things with no luck, but then closing and re-opening Visual Studio fixed the problem.

Meekohi
  • 10,390
  • 6
  • 49
  • 58
-1

I have this problem exactly and found the answer. I use class library (.NETStandard) but necessary class library (.NET MVC)

With this class library my proj work correct

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 18 '23 at 04:37