Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet ef migrations fails with "...doesn't reference Microsoft.EntityFrameworkCore.Design ..." but design package is added #35544

Closed
cerkoid opened this issue Jan 28, 2025 · 13 comments

Comments

@cerkoid
Copy link

cerkoid commented Jan 28, 2025

Question

We are having problems with ef tools.

Your startup project 'ENS3.Migrations' doesn't reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.

But Microsoft.EntityFrameworkCore.Design is referenced and package manager restores the package. What could be wrong, how to diagnose the problem?

Your code

Part of ENS3.Migrations.csproj file that is added using package manager
<ItemGroup>
  <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
  </PackageReference>
</ItemGroup>

Stack traces


Verbose output


EF Core version

9.0.0

Database provider

No response

Target framework

.NET 9.0

Operating system

Windows 11

IDE

Microsoft Visual Studio Community 2022 (64-bit) - Preview Version 17.13.0 Preview 3.0

@cerkoid cerkoid changed the title dotnet ef migrations fails with dotnet ef migrations fails with "...doesn't reference Microsoft.EntityFrameworkCore.Design ..." Jan 29, 2025
@cerkoid cerkoid changed the title dotnet ef migrations fails with "...doesn't reference Microsoft.EntityFrameworkCore.Design ..." dotnet ef migrations fails with "...doesn't reference Microsoft.EntityFrameworkCore.Design ..." but design package is added Jan 29, 2025
@aldrashan
Copy link

You need to build the project once after adding the package, otherwise you get that error.

@geertdoornbos
Copy link

You need to build the project once after adding the package, otherwise you get that error.

Sorry, doesn't help.

    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.1" />
dotnet build 

Successful

dotnet ef migrations add MigrationX

Failed - "Your startup project 'Prj.EntityFramework.SqlServer' doesn't reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again."

dotnet ef

Entity Framework Core .NET Command-line Tools 9.0.1

@adamburgess
Copy link

Can I also pipe in here and say this happened to me today. I'm not sure exactly when it started to happen, but it was working fine a week or two ago, and I don't think I've changed anything apart from keeping VS 2022 preview up to date.

Removing the PrivateAssets did fix it – but this isn't a solution as I don't want the design dlls to be in the published output.

I am also using the scaffold command, not migrations.

@aldrashan
Copy link

Strange, it's working in my console program.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.*">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.*" />
  </ItemGroup>
</Project>

I'm using VS Enterprise 2022 version 17.12.4 though, not a preview version.

PM> dotnet ef dbcontext scaffold "..." Microsoft.EntityFrameworkCore.SqlServer -o MSSQL/Db -c OurDbContext -f --no-onconfiguring --no-pluralize
Build started...
Build succeeded.
PM> 

@roji
Copy link
Member

roji commented Jan 30, 2025

This is something that generally works - I can't repro this, and almost all EF users use dotnet ef migrations successfully. I'm not saying there isn't a problem here, but we're going to need precise repro steps in order to investigate here.

@cerkoid
Copy link
Author

cerkoid commented Jan 30, 2025

I don't know... I have 2 different projects on two computers, both running windows 11 with Microsoft Visual Studio Community 2022 (64-bit) - Preview Version 17.13.0 Preview 3.0. EF core tools upgraded to latest version, migration fails. I understand that most users don't have problems. We are using ef core for years, but this problem occured this week on both computers and I have no idea what changed, because source code did not...

Sample project that does not work on my current setup:
EFCoreTest.zip

cmd: dotnet ef migrations add Initial --context TestDbContext -o Migrations/PostgreSQL/Test

outputs:

Build started...
Build succeeded.
Your startup project 'EFCoreTest' doesn't reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.

@thoemmi
Copy link

thoemmi commented Jan 30, 2025

I experienced the same issue since Preview 3 of Visual Studio (.NET SDK 9.0.200-preview.0.25057.12)
My workaround was to add a global.json to pin the latest stable SDK:

dotnet new globaljson --sdk-version 9.0.102

@cincuranet
Copy link
Contributor

Using your repro, I'm not able to reproduce it. No error and migration is created.

Using:

.NET SDK:
 Version:           9.0.102
 Commit:            cb83cd4923
 Workload version:  9.0.100-manifests.4a54b1a6
 MSBuild version:   17.12.18+ed8c6aec5

Host:
  Version:      9.0.1
  Architecture: x64
  Commit:       c8acea2262

Unless we get repro, there's not much we can do.

@thoemmi
Copy link

thoemmi commented Feb 3, 2025

The error does not occur with the 9.0.102 but the current preview, as several comments stated above.

I'm using:

.NET SDK:
 Version:           9.0.200-preview.0.25057.12
 Commit:            cf6faae8d1
 Workload version:  9.0.200-manifests.693890c1
 MSBuild version:   17.13.0-preview-24569-04+8f6b

Host:
  Version:      9.0.1
  Architecture: x64
  Commit:       c8acea2262

@cincuranet
Copy link
Contributor

@AndriySvyryd are we interested, given it is happening on preview version?

@thoemmi
Copy link

thoemmi commented Feb 3, 2025

Well, IMHO preview versions are released so everyone can check that the next official release won't break your stuff. So this issue can be seen as a hint that EF migrations might break with the next minor release of .NET SDK.

@AndriySvyryd
Copy link
Member

This is a duplicate of #35265, it will be fixed in EF 10.

As a workaround add <Publish>true</Publish>. It will still be added to the output folder, but it won't be referenced, so you can just delete it:

    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <Publish>true</Publish>
    </PackageReference>

@AndriySvyryd
Copy link
Member

Added this to breaking changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants