I've got a Solution with many projects.
One of them (Domain
) is a .NET Standard 2.0 project where I made my EF Core DbContext
implementation for which I want to enable database migrations.
I saw various blogs and Q/A forums where the problem was explained but none of the proposed solutions seem to work for me because of the .NET Core newer version or (probably) for my particular solution configuration.
Solution projects
- Engine (.NET Core 2.1 Console App)
- Web API (.NET Core 2.1 Library)
- Application (.NET Core 2.1 Library)
- Domain (.NET Standard 2.0 Library)
- WindowsService (.NET Core 2.1 Console App)
The WindowsService
is the Startup project, where an instance of the Engine
is created and encapsulated to run as Windows Service or Console application (for debug).
The Engine
is the real core application, where an instance of Kestrel
self-host Web server is configured as Web API and instantieted. Also other components are instantiated and stay alive (UDP listener, machine watchdog, etc...).
WebAPI
has Startup
class but no Program
class, since all the configuration and the Web server start is done inside Engine.Program.cs
class.
Dependencies
- WindowsService => Engine
- Engine => WebAPI
- WebAPI => Application, Domain
- Application => Domain
The first attempt was to simply launch add-migration Initial
from PMC with Domain
project as target, but it turns to:
Unable to create an object of type 'MyDbContext'. Add an implementation of 'IDesignTimeDbContextFactory' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.
Then I followed the proposed solution on this question, but:
add-migration Initial
from PMC, after setting MyWebAPI
(with noProgram
class) as startup project, turns to:It was not possible to find any compatible framework version The specified framework 'Microsoft.NETCore.App', version '2.1.0' was not found.
- Check application dependencies and target a framework version installed at: C:\Program Files\dotnet\
- Installing .NET Core prerequisites might help resolve this problem: http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
- The .NET Core framework and SDK can be installed from: https://aka.ms/dotnet-download
- The following versions are installed: 2.0.5 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 2.0.6 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 2.0.7 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 2.0.9 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 2.1.2 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
add-migration Initial
from PMC, after adding an additional target framework (netcoreapp2.1
) to the Domain library project file, leads me to the same error as the 1st attempt.add-migration Initial
from PMC, after adding a reference toMicrosoft.EntityFrameworkCore.SqlServer.Design v1.1.6
always leads to same error as the 1st attempt.
What should I do?
UPDATE
This is the new Domain.csproj
file after removing the unecessary libraries references.
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
</ItemGroup>
All libraries in all projects are up to date.