I'm trying to create an UWP application with an opportunity to launch many quiz based games. For this reason I have a Core project(UWP) which will display all the gamemodes. Each gamemode is implemented in its own project, and I'd like to add a separate Data Access Layer to every gamemode. (The DAL would implement the Repository pattern)
So, my Core project (UWP) references the AllOrNothing(Class Library Universal Windows) project. Until this point it's fine. When I'm trying to add a project which will used by the Entity Framework I don't really know which type of project should I choose.
- If I see it correctly only .NET Standard 2.0 and the specific UWP class libraries can be referenced from the AllOrNothing(UWP Library) project. For example if I try to reference a .NET 6 project from the UWP library it throws an error.
So I added a .NET Standard 2.0 Library, and installed the EF(version 6.4.4), and EF Core(version 3.1.22)
When I run the command add-migration Init
, it says the following:
Project 'QuizProgram.Core' targets framework '.NETStandard'. The Entity Framework Package Manager Console Tools don't support this framework.
(QuizProgram.Core
is my startup project)
I don't really understand the problem, and can't really solve it.
I'm using Visual Studio 2022.
CodePudding user response:
You cannot reference .NET Core/5/6 or Standard 2.1 projects from UWP, as you have found out yourself. You can reference .NET Framework 4.8 or earlier (if your UWP project is the same version or later as the target) or .NET Standard 2.0.
If you might want to share the library with .NET Core/5/6 then you need to select .NET Standard 2.0. If you don't, then .NET 4.8 is a better choice as it is a newer version of the framework.
It sounds like you are using .NET Standard 2.0. In this case you will need to use DF 3.1.22 or earlier for compatibility purposes. You will also need to use a startup project that references either .NET framework or .NET Core and also the .NET Standard library where you have your EF model defined, because .NET Standard 2.0 cannot perform the migrations. The syntax for this is as follows:
dotnet ef migrations script --project YourNetStandardEFModel --startup-project YourNet48ProjectReferencingIt
CodePudding user response:
I created a project with .NET Framework 4.8 (EFHelper), referenced the EFModel project from it, and after running the command you suggested, I got the following issue:
Unable to retrieve project metadata. Ensure it's an SDK-style project. If you're using a custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option.
I've run this PMC console as well: Add-Migration Initial -Project QuizGame.AllOrNothing.Repository -StartupProject EFHelper but this gave me another error:
The interesting part of it, that the error message lies, because the EFHelper is not .NET Standard but .NET Framework 4.8, it's 100%