I'm using 2022.3.4f1 of the Unity game engine, which is supposed to support NET Standard 2.1. However when I try to install the Nuget package for Microsoft.EntityFrameworkCore v5.0.17, which targets NET Standard 2.1, I get the following error:
Attempting to gather dependency information for package 'Microsoft.EntityFrameworkCore.5.0.17' with respect to project 'Assembly-CSharp', targeting '.NETFramework,Version=v4.7.1'
Gathering dependency information took 2.79 sec
Attempting to resolve dependencies for package 'Microsoft.EntityFrameworkCore.5.0.17' with DependencyBehavior 'Lowest'
One or more unresolved package dependency constraints detected in the existing packages.config file. All dependency constraints must be resolved to add or update packages. If these packages are being updated this message may be ignored, if not the following error(s) may be blocking the current package operation: 'Microsoft.EntityFrameworkCore.Relational 3.1.32 constraint: Microsoft.EntityFrameworkCore (>= 3.1.32)'
Resolving dependency information took 0 ms
Resolving actions to install package 'Microsoft.EntityFrameworkCore.5.0.17'
Resolved actions to install package 'Microsoft.EntityFrameworkCore.5.0.17'
Retrieving package 'Microsoft.EntityFrameworkCore 5.0.17' from 'nuget.org'.
Install failed. Rolling back...
Package 'Microsoft.EntityFrameworkCore.5.0.17' does not exist in project 'Assembly-CSharp'
Package 'Microsoft.EntityFrameworkCore.5.0.17' does not exist in folder 'C:\Users\Atlinx\Documents\Unity\Unity Projects\QuestDispatch\packages'
Executing nuget actions took 1.45 sec
Install-Package : Could not install package 'Microsoft.EntityFrameworkCore 5.0.17'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.7.1', but the package does not contain any assembly
references or content files that are compatible with that framework. For more information, contact the package author.
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore -Version 5.0.17
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Time Elapsed: 00:00:04.7149747
I feel like it's caused by the csproj having the following line:
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
From my research, NET Framework versions (v4.6, v4.7 ...) all the way up to the last version (v4.8) target only NET Standard 2.0. However, I'm not sure how I can change it to use NET Standard 2.1 instead.
Unity is very tricky for importing NuGet packages. Need to very careful and using only .NET Standard 2.0 or 2.1 versions of the NuGet packages. Also, EntityFrameworkCore requires database provider, such as SQLite provider to work properly. That triggers another chain of dependencies to include. Each platform has a unique sub-set of dependencies. To be honest that is really time consuming to make all of that to work.
That is why I made the bundle package, that would include all required dependencies for Unity project to let it work at least on these platforms: Windows, Android, iOS, MacOS. There is the bundle package - Unity + EFCore + SQLite.
Please let me know if you find any issues, I would be glad to polish it. It works for my project on all the mentioned platforms. Just please make sure you switched project to .NET Standard 2.0 or 2.1 as mentioned in the README.