前言:abp中使用這個命令時,會出現比較多的問題,有無法識別的,也有缺少組件的,這里匯總以下我遇到情況,也解決下遇到同樣問題的同學
報錯目錄:
問題1描述:使用Add-Migration xxx,控制台輸出
1 Your target project 'xxx.EntityFrameworkCore.DbMigrations' doesn't reference EntityFramework. 2 This package is required for the Entity Framework Core Tools to work. 3 Ensure your target project is correct, install the package, and try again.
問題1解決方案:
打開NuGet,所有項目已安裝的EntityFrameworkCore.Tools(下文用Tools代替)與EntityFrameworkCore.Design(下文用Design代替)卸載,DbMigrations重新安裝Tools與Design,保證EntityFrameworkCore.Tools與EntityFrameworkCore.Design版本對應,過程中可能要求其他層安裝Tools與Design,根據提示的錯誤說那個項目缺少引用就引用Tools或者Design。
問題1備注:解決Tools與Design后,可能會出現
1 System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. 3 ---> System.TypeLoadException: Method 'Create' in type 'Microsoft.EntityFrameworkCore.SqlServer.Query.Internal.SqlServerSqlTranslatingExpressionVisitorFactory' from assembly 'Microsoft.EntityFrameworkCore.SqlServer, Version=3.1.6.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation. 5 at Microsoft.Extensions.DependencyInjection.SqlServerServiceCollectionExtensions.AddEntityFrameworkSqlServer(IServiceCollection serviceCollection) 7 at Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal.SqlServerOptionsExtension.ApplyServices(IServiceCollection services) 9 at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.ApplyServices(IDbContextOptions options, ServiceCollection services) 11 at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayClass4_0.<GetOrAdd>g__BuildServiceProvider|3() 13 at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayClass4_0.<GetOrAdd>b__2(Int64 k) 15 at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) 17 at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.GetOrAdd(IDbContextOptions options, Boolean providerRequired) 19 at Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptions options) 21 at Volo.Abp.EntityFrameworkCore.AbpDbContext`1..ctor(DbContextOptions`1 options) 23 at Pro212.EntityFrameworkCore.DbMigrations.EntityFrameworkCore.Pro212MigrationsDbContext..ctor(DbContextOptions`1 options) in D:\abp\Pro212\src\Pro212.EntityFrameworkCore.DbMigrations\EntityFrameworkCore\Pro212MigrationsDbContext.cs:line 11 25 at Pro212.EntityFrameworkCore.DbMigrations.EntityFrameworkCore.Pro212MigrationsDbContextFactory.CreateDbContext(String[] args) in D:\abp\Pro212\src\Pro212.EntityFrameworkCore.DbMigrations\EntityFrameworkCore\Pro212MigrationsDbContextFactory.cs:line 20 27 --- End of inner exception stack trace --- 29 at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) 31 at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 33 at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) 35 at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContextFromFactory(Type factory, Type contextType) 37 at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass16_0.<FindContextFactory>b__1() 39 at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory) 41 at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType) 43 at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace) 45 at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace) 47 at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0() 49 at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0() 51 at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) 53 Exception has been thrown by the target of an invocation.
此錯誤說EntityFrameworkCore.SqlServer版本問題,重新安裝EntityFrameworkCore.SqlServer,同樣與Tools與Design版本對應即可。
其他錯誤待更新。
