我是UWP的新手,我正在尝试使用EntityFrameworkCore构建我的第一个应用程序。我的设置是这样:
Visual Studio 2019
UWP target version - W10 version 1903
UWP min verion - W10 Fall Creators Update
Nuget installed packages:
Microsoft.EntityFrameworkCore - 2.2.6
Microsoft.EntityFrameworkCore.Design - 2.2.6
Microsoft.EntityFrameworkCore.Sqlite - 2.2.6
Microsoft.EntityFrameworkCore.Tools - 2.2.6
(3.0.1 the latest versions support only .NETStandard 2.1 so I can't use them in a UWP app)
Microsoft.NETCore.UniversalWindowsPlatform - 6.2.9
我创建了模型和DBContext,现在需要创建数据库,唯一的方法是通过迁移来完成。这是我遇到问题的地方:
我不能使用Nuget控制台,因为工具不支持UWP。
PM> Add-Migration InitialCreate
Startup project 'Test' is a Universal Windows Platform app. This version of the Entity Framework Core Package Manager Console Tools doesn't support this type of project.
由于不同的错误,我无法使用dotnet-ef:
$ dotnet tool install --global dotnet-ef --version 3.0.0
$ dotnet ef migrations add InitialCreate
C:\Users\admin\Desktop\rev\Test.csproj(219,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\3.0.100\Microsoft\WindowsXaml\v16.0\Microsoft.Windows.UI.Xaml.CSharp.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. Unable to retrieve project metadata. Ensure it's an MSBuild-based .NET Core project. If you're using custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option.
我被完全封锁了。除了实体框架,我还能尝试其他什么吗?
更新
我编辑了.csproj并将标记替换为Visual Studio文件夹中的其他URL,看来它可以通过此错误。
但是我还有其他东西:
$ dotnet ef migrations add InitialCreate
C:\Users\admin\Desktop\rev\obj\Test.csproj.EntityFrameworkCore.targets(4,5): error MSB4006: There is a circular dependency in the target dependency graph involving target "GetEFProjectMetadata". [C:\Users\admin\Desktop\rev\Test.csproj]
Unable to retrieve project metadata. Ensure it's an MSBuild-based .NET Core project. If you're using custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option.
答案 0 :(得分:0)
如错误消息中所述,如果您在UWP项目中使用dotnet-CLI进行数据库迁移管理,则不支持
当前,UWP项目仍使用.Net Standard 2.0
,并且不支持Asp.Net Core 3
的dotnet-CLI。
如果要使用dotnet-CLI管理数据库,则只能在UWP项目之外进行。
最诚挚的问候。