[英]Project X targets framework '.NETStandard'. The Entity Framework Package Manager Console Tools don't support this framework
I'm trying to create a EF 6.4 migration in my solution which has net472 projects and netstandard projects, and I'm getting the following error:我正在尝试在具有 net472 项目和 netstandard 项目的解决方案中创建 EF 6.4 迁移,但出现以下错误:
Project 'ESP.Console' targets framework '.NETStandard'.项目“ESP.Console”以框架“.NETStandard”为目标。 The Entity Framework Package Manager Console Tools don't support this framework.实体框架 Package 管理器控制台工具不支持此框架。
However, the 'ESP.Console' app doesn't target .NETStandard, it's targetting net472:但是,“ESP.Console”应用程序不针对 .NETStandard,它针对的是 net472:
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<LangVersion>7.3</LangVersion>
<OutputType>Exe</OutputType>
</PropertyGroup>
I have ESP.Console
console app set as my startup project, and I have the ESP.Data
project as my default project in the Package Manager console.我将ESP.Console
控制台应用程序设置为我的启动项目,并在 Package 管理器控制台中将ESP.Data
项目作为我的默认项目。
This is the setup for ESP.Data.csproj
:这是ESP.Data.csproj
的设置:
<PropertyGroup>
<TargetFrameworks>netstandard2.1;net472</TargetFrameworks>
<EmbeddedResourceUseDependentUponConvention>true</EmbeddedResourceUseDependentUponConvention>
</PropertyGroup>
I need this to target both netstandard and net472 while I am in the process of converting other applications in the solution to run on .net core.当我正在转换解决方案中的其他应用程序以在 .net 内核上运行时,我需要它来针对 netstandard 和 net472。
Why am I getting this error?为什么我会收到此错误? Is there another command like dotnet ef
I can use that will work with my EF 6.4 project?是否有另一个命令,如dotnet ef
可以用于我的 EF 6.4 项目?
We've used EF migrations on this solution hundreds of times, but since the last time I needed to run a migration we've done two major changes to the solution- converted all the csproj files to use the new format (with PackageReference, etc) and converted the core projects to target either .net standard 2.0 or 2.1 where needed.我们已经在这个解决方案上使用了数百次 EF 迁移,但是自从我上次需要运行迁移以来,我们对解决方案进行了两项重大更改 - 将所有 csproj 文件转换为使用新格式(使用 PackageReference 等) 并在需要时将核心项目转换为针对 .net 标准 2.0 或 2.1。 So I think the issue is related to that.所以我认为这个问题与此有关。
Attempting to change ESP.Console application to run as netcoreapp3.1
gave the same error.尝试将 ESP.Console 应用程序更改为作为netcoreapp3.1
运行时会出现相同的错误。
I have found a solution to my problem, though it is a bit messy since I will need to make a temporary change to a csproj file in order to get this to run.我找到了解决问题的方法,尽管它有点混乱,因为我需要对 csproj 文件进行临时更改才能使其运行。
In my case, the ESP.Data
(the project housing my DbContext
) was targeting both net472
and netstandard2.1
, I altered the Data project to remove the netstandard2.1
target framework.就我而言, ESP.Data
(包含我的DbContext
的项目)同时针对net472
和netstandard2.1
,我更改了 Data 项目以删除netstandard2.1
目标框架。 It seems there is a bug in VS that is saying that the StartupProject targets NetStandard instead of saying that the Target project does. VS 中似乎有一个错误,它说 StartupProject 以 NetStandard 为目标,而不是说 Target 项目确实如此。 After I create the migration, I can add the target back again.创建迁移后,我可以再次添加目标。
I will be moving to .net core compilation soon, and will therefore need that netstandard 2.1 target at some point, so I'm not sure what I'll do when that comes.我将很快转向 .net 核心编译,因此在某些时候需要 netstandard 2.1 目标,所以我不确定当它到来时我会做什么。 I may need to preserve a net472 console application to use in the future and continue targeting net472 in my data project after that migration is done in order to continue to create migrations.我可能需要保留一个 net472 控制台应用程序以供将来使用,并在迁移完成后继续在我的数据项目中定位 net472,以便继续创建迁移。
I had a simular problem.我有一个类似的问题。
My problem was, that I was targeting netcoreapp3.1
with my startup project and used Entity Framework 6 tools
.我的问题是,我的启动项目以netcoreapp3.1
为目标,并使用了Entity Framework 6 tools
。
When I switched to EntityFrameworkCore tools
it worked.当我切换到EntityFrameworkCore tools
时,它起作用了。
Might be a bug in Visual Studio -- I was seeing this error after I changed the Startup Project to the correct project with my migrations, even though my project uses .NET Framework 4.8.可能是 Visual Studio 中的一个错误——即使我的项目使用 .NET Framework 4.8,在我将启动项目更改为正确的项目后,我还是看到了这个错误。
Tried several things with no luck, but then closing and re-opening Visual Studio fixed the problem.尝试了几件事没有运气,但随后关闭并重新打开 Visual Studio 解决了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.