Entity framework targetInvestment异常脚手架DbContext EF 5

Entity framework targetInvestment异常脚手架DbContext EF 5,entity-framework,entity-framework-core,Entity Framework,Entity Framework Core,我正在尝试运行以下脚手架,该项目位于.NET5中。我得到了这个错误 我所有的项目都说 <PropertyGroup> <TargetFramework>net5.0</TargetFramework> net5.0 引用efcore的一个项目 <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.4" />

我正在尝试运行以下脚手架,该项目位于.NET5中。我得到了这个错误

我所有的项目都说

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>

net5.0
引用efcore的一个项目

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="5.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="5.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.4">

错误

System.Reflection.TargetInvocationException:调用的目标已引发异常。
--->System.TypeLoadException:无法从程序集“Microsoft.EntityFrameworkCore,Version=5.0.4.0,Culture=neutral,PublicKeyToken=adb9793829ddae60”加载类型“Microsoft.EntityFrameworkCore.Internal.SemanticVersionComparer”。
位于Microsoft.EntityFrameworkCore.Design.OperationExecutor..ctor(IOperationReportHandler reportHandler,IDictionary参数)
---内部异常堆栈跟踪的结束---
在System.RuntimeMethodHandle.InvokeMethod(对象目标、对象[]参数、签名符号、布尔构造函数、布尔WrapeExceptions)
在System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr、Binder Binder、Object[]参数、CultureInfo区域性)
位于System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr、Binder Binder、Object[]args、CultureInfo区域性)
在System.Activator.CreateInstance(类型类型、BindingFlags bindingAttr、Binder Binder、对象[]参数、CultureInfo区域性、对象[]ActivationAttribute)
位于System.Activator.CreateInstance(类型,对象[]args)
位于Microsoft.EntityFrameworkCore.Tools.ReflectionOperationExecutor..ctor(字符串汇编、字符串startupAssembly、字符串projectDir、字符串dataDirectory、字符串根命名空间、字符串语言、字符串[]remainingArguments)
位于Microsoft.EntityFrameworkCore.Tools.Commands.ProjectCommandBase.CreateExecutor(字符串[]剩余参数)
位于Microsoft.EntityFrameworkCore.Tools.Commands.DbContextScaffoldCommand.Execute(字符串[]args)
在Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.c__DisplayClass0_0.b_0(字符串[]参数)中
在Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(字符串[]args)
位于Microsoft.EntityFrameworkCore.Tools.Program.Main(字符串[]args)
调用的目标已引发异常。
Saffold命令

Scaffold DbContext“服务器=1.1.1.11433;初始目录=First;持久化 安全信息=False;用户 ID=data;Password=data;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;连接 超时=30;“Microsoft.EntityFrameworkCore.SqlServer-OutputDir Model/DB-Force-Context S3Context-Project S3.Core.DataSync.Framework -数据同步销售


我有3个项目1个项目包含EF核心。如果我加载所有三个项目,并将引用EF Core的项目设置为“设置为启动”,我就不再有这个问题。一旦我设置了启动项目应该是什么,我就得到了这个错误

你在混合版本吗?请分享您的.csproj内容请参见修订后的问题
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Internal.SemanticVersionComparer' from assembly 'Microsoft.EntityFrameworkCore, Version=5.0.4.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor..ctor(IOperationReportHandler reportHandler, IDictionary args)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, Object[] args)
   at Microsoft.EntityFrameworkCore.Tools.ReflectionOperationExecutor..ctor(String assembly, String startupAssembly, String projectDir, String dataDirectory, String rootNamespace, String language, String[] remainingArguments)
   at Microsoft.EntityFrameworkCore.Tools.Commands.ProjectCommandBase.CreateExecutor(String[] remainingArguments)
   at Microsoft.EntityFrameworkCore.Tools.Commands.DbContextScaffoldCommand.Execute(String[] args)
   at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.<>c__DisplayClass0_0.<Configure>b__0(String[] args)
   at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
   at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
Exception has been thrown by the target of an invocation.