net core生成数据库,使用Scaffold-DbContext报错“‘Scaffold-DbContext’ is not recognized as the name of a cmdlet”
2017-03-02 14:46
507 查看
win7,64位,vs2015
net core生成数据库,使用Scaffold-DbContext报错“‘Scaffold-DbContext’ is not recognized as the name of a cmdlet”
学习的生成数据库信息的文章来自:http://www.cnblogs.com/baobaodong/p/5871357.html
运行的代码是:PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
![](https://img-blog.csdn.net/20170302144135085?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveGluZ3l1aGFpbGluZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
就在网上搜索下,找到一篇:http://www.genshuixue.com/i-cxy/p/12865486
![](https://img-blog.csdn.net/20170302144237696?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveGluZ3l1aGFpbGluZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
之后我吧代码加上,再次运行 Scaffold-DbContext
![](https://img-blog.csdn.net/20170302144340706?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveGluZ3l1aGFpbGluZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
提示我powershell版本需要升级,我就从网上下载一个powershell3进行安装,重新启动电脑,但是还是不行,看到如下错误代码
下面看到的错误信息,有看到包名就进行安装下
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
System.AggregateException: One or more errors occurred. ---> Microsoft.EntityFrameworkCore.Design.OperationException: Unable to find design-time provider assembly. Please install the Microsoft.EntityFrameworkCore.SqlServer.Design NuGet package and ensure that
the package is referenced by the project. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.SqlServer.Design, Version=1.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies.
系统锟揭诧拷锟斤拷指锟斤拷锟斤拷锟侥硷拷锟斤拷 at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean
forIntrospection, Boolea n suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean
suppressSecurityChecks)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.GetProviderDesignTimeServices(String provider, Boolean throwOnError)
--- End of inner exception stack trace ---
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.GetProviderDesignTimeServices(String provider, Boolean throwOnError)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.Build(String provider)
at Microsoft.EntityFrameworkCore.Design.DatabaseOperations.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overw
riteFiles, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Design.Internal.OperationExecutor.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnota
tions, Boolean overwriteFiles, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Tools.Cli.DbContextScaffoldCommand.<ExecuteAsync>d__1.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
---> (Inner Exception #0) Microsoft.EntityFrameworkCore.Design.OperationException: Unable to find design-time provider assembly. Please install the Microsoft.EntityFrameworkCore.SqlServer.Design NuGet package and ensure that the package is referenced by th
e project. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.SqlServer.Design, Version=1.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. 系统锟揭诧拷锟斤拷指锟斤拷锟斤拷锟侥硷拷锟斤拷
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolea
n suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean
suppressSecurityChecks)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.GetProviderDesignTimeServices(String provider, Boolean throwOnError)
--- End of inner exception stack trace ---
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.GetProviderDesignTimeServices(String provider, Boolean throwOnError)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.Build(String provider)
at Microsoft.EntityFrameworkCore.Design.DatabaseOperations.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overw
riteFiles, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Design.Internal.OperationExecutor.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnota
tions, Boolean overwriteFiles, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Tools.Cli.DbContextScaffoldCommand.<ExecuteAsync>d__1.MoveNext()<---
One or more errors occurred.
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
C:\Users\Administrator\Desktop\test7\src\test7\project.json(21,54): warning NU1012: Dependency conflict. Microsoft.EntityFrameworkCore.SqlServer.Design 1.1.0 expected Microsoft.EntityFrameworkCore.SqlServer >= 1.1.0 but received 1.0.1 C:\Users\Administrator\Desktop\test7\src\test7\project.json(24,43):
warning NU1012: Dependency conflict. Microsoft.EntityFrameworkCore 1.1.0 expected Microsoft.Extensions.Logging >= 1.1.0 but received 1.0.0
C:\Users\Administrator\Desktop\test7\src\test7\Modles\FirstAppDemoDbContext.cs(14,32): warning CS0114: 'FirstAppDemoDbContext.OnConfiguring(DbContextOptionsBuilder)' hides inherited member 'DbContext.OnConfiguring(DbContextOptionsBuilder)'. To make the cur
rent member override that implementation, add the override keyword. Otherwise add the new keyword.
C:\Users\Administrator\Desktop\test7\src\test7\Startup.cs(69,30): warning CS0168: The variable 'ex' is declared but never used
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest def
inition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
C:\Users\Administrator\Desktop\test7\src\test7\project.json(21,54): warning NU1012: Dependency conflict. Microsoft.EntityFrameworkCore.SqlServer.Design 1.1.0 expected Microsoft.EntityFrameworkCore.SqlServer >= 1.1.0 but received 1.0.1 C:\Users\Administrator\Desktop\test7\src\test7\Modles\FirstAppDemoDbContext.cs(14,32):
warning CS0114: 'FirstAppDemoDbContext.OnConfiguring(DbContextOptionsBuilder)' hides inherited member 'DbContext.OnConfiguring(DbContextOptionsBuilder)'. To make the cur rent member override that implementation, add the override keyword. Otherwise add the
new keyword.
C:\Users\Administrator\Desktop\test7\src\test7\Startup.cs(69,30): warning CS0168: The variable 'ex' is declared but never used
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest def
inition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
C:\Users\Administrator\Desktop\test7\src\test7\Modles\FirstAppDemoDbContext.cs(14,32): warning CS0114: 'FirstAppDemoDbContext.OnConfiguring(DbContextOptionsBuilder)' hides inherited member 'DbContext.OnConfiguring(DbContextOptionsBuilder)'. To make the current
member override that implementation, add the override keyword. Otherwise add the new keyword. C:\Users\Administrator\Desktop\test7\src\test7\Startup.cs(69,30): warning CS0168: The variable 'ex' is declared but never used
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest def
inition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
C:\Users\Administrator\Desktop\test7\src\test7\Modles\FirstAppDemoDbContext.cs(14,32): warning CS0114: 'FirstAppDemoDbContext.OnConfiguring(DbContextOptionsBuilder)' hides inherited member 'DbContext.OnConfiguring(DbContextOptionsBuilder)'. To make the current
member override that implementation, add the override keyword. Otherwise add the new keyword. C:\Users\Administrator\Desktop\test7\src\test7\Startup.cs(69,30): warning CS0168: The variable 'ex' is declared but never used
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest def
inition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
C:\Users\Administrator\Desktop\test7\src\test7\Startup.cs(69,30): warning CS0168: The variable 'ex' is declared but never used Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest def inition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition
does not match the assembly reference. (Exception from HRESULT: 0x80131040) at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition
does not match the assembly reference. (Exception from HRESULT: 0x80131040) at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
之前上面看到的错误信息,有看到包名就进行安装下
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
System.InvalidOperationException: The following file(s) already exist in directory C:\Users\Administrator\Desktop\test7\src\test7\Modles: Employee.cs. Use the Force flag to overwrite these files.
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator.CheckOutputFiles(String outputPath, String dbContextClassName, IModel metadataModel, Boolean overwriteFiles)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator.GenerateAsync(ReverseEngineeringConfiguration configuration, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContextAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean
overwriteFiles, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.<ScaffoldContextImpl>d__22.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass4_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
The following file(s) already exist in directory C:\Users\Administrator\Desktop\test7\src\test7\Modles: Employee.cs. Use the Force flag to overwrite these files.
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
System.InvalidOperationException: The following file(s) already exist in directory C:\Users\Administrator\Desktop\test7\src\test7\Modles: Employee.cs. Use the Force flag to overwrite these files.
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator.CheckOutputFiles(String outputPath, String dbContextClassName, IModel metadataModel, Boolean overwriteFiles)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator.GenerateAsync(ReverseEngineeringConfiguration configuration, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContextAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean
overwriteFiles, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.<ScaffoldContextImpl>d__22.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass4_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
The following file(s) already exist in directory C:\Users\Administrator\Desktop\test7\src\test7\Modles: Employee.cs. Use the Force flag to overwrite these files.
如上说的问题是当前数据库已经存在model里面的类的表了,所以我就改了下数据库里的表的名称,如下就执行成功了
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
PM>
![](https://img-blog.csdn.net/20170302144114471?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveGluZ3l1aGFpbGluZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
如果对ASP.NET Core包进行升级的话,版本从1.0至1.1,或其他的包进行了更新之后报错
Scaffold-DbContext : The term 'Scaffold-DbContext' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path
was included, verify that th
e path is correct and try again.
At line:1 char:1
+ Scaffold-DbContext "Data Source=.;Initial Catalog=testData;User ID=sa;Passw ...
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Scaffold-DbContext:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
这样就对“Microsoft.EntityFrameCore”相关的包进行更新下就可以了
如果提示连接数据库语句的问题,看看是不是有安装多个sqlserver版本的数据库,进行区别下就可以了。
如果有找到文档说是需要升级下"Microsoft.EntityFrameworkCore.Tools.DotNet":"1.0.0-preview3-final",安装这个包的时候就会提示此包不支持当前的nuget,这个是在vs2017下应该可以,这个是个人猜测和看文档说的,没有具体实践。
net core生成数据库,使用Scaffold-DbContext报错“‘Scaffold-DbContext’ is not recognized as the name of a cmdlet”
学习的生成数据库信息的文章来自:http://www.cnblogs.com/baobaodong/p/5871357.html
运行的代码是:PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
就在网上搜索下,找到一篇:http://www.genshuixue.com/i-cxy/p/12865486
之后我吧代码加上,再次运行 Scaffold-DbContext
提示我powershell版本需要升级,我就从网上下载一个powershell3进行安装,重新启动电脑,但是还是不行,看到如下错误代码
下面看到的错误信息,有看到包名就进行安装下
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
System.AggregateException: One or more errors occurred. ---> Microsoft.EntityFrameworkCore.Design.OperationException: Unable to find design-time provider assembly. Please install the Microsoft.EntityFrameworkCore.SqlServer.Design NuGet package and ensure that
the package is referenced by the project. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.SqlServer.Design, Version=1.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies.
系统锟揭诧拷锟斤拷指锟斤拷锟斤拷锟侥硷拷锟斤拷 at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean
forIntrospection, Boolea n suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean
suppressSecurityChecks)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.GetProviderDesignTimeServices(String provider, Boolean throwOnError)
--- End of inner exception stack trace ---
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.GetProviderDesignTimeServices(String provider, Boolean throwOnError)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.Build(String provider)
at Microsoft.EntityFrameworkCore.Design.DatabaseOperations.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overw
riteFiles, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Design.Internal.OperationExecutor.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnota
tions, Boolean overwriteFiles, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Tools.Cli.DbContextScaffoldCommand.<ExecuteAsync>d__1.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
---> (Inner Exception #0) Microsoft.EntityFrameworkCore.Design.OperationException: Unable to find design-time provider assembly. Please install the Microsoft.EntityFrameworkCore.SqlServer.Design NuGet package and ensure that the package is referenced by th
e project. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.SqlServer.Design, Version=1.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. 系统锟揭诧拷锟斤拷指锟斤拷锟斤拷锟侥硷拷锟斤拷
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolea
n suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean
suppressSecurityChecks)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.GetProviderDesignTimeServices(String provider, Boolean throwOnError)
--- End of inner exception stack trace ---
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.GetProviderDesignTimeServices(String provider, Boolean throwOnError)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.Build(String provider)
at Microsoft.EntityFrameworkCore.Design.DatabaseOperations.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overw
riteFiles, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Design.Internal.OperationExecutor.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnota
tions, Boolean overwriteFiles, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Tools.Cli.DbContextScaffoldCommand.<ExecuteAsync>d__1.MoveNext()<---
One or more errors occurred.
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
C:\Users\Administrator\Desktop\test7\src\test7\project.json(21,54): warning NU1012: Dependency conflict. Microsoft.EntityFrameworkCore.SqlServer.Design 1.1.0 expected Microsoft.EntityFrameworkCore.SqlServer >= 1.1.0 but received 1.0.1 C:\Users\Administrator\Desktop\test7\src\test7\project.json(24,43):
warning NU1012: Dependency conflict. Microsoft.EntityFrameworkCore 1.1.0 expected Microsoft.Extensions.Logging >= 1.1.0 but received 1.0.0
C:\Users\Administrator\Desktop\test7\src\test7\Modles\FirstAppDemoDbContext.cs(14,32): warning CS0114: 'FirstAppDemoDbContext.OnConfiguring(DbContextOptionsBuilder)' hides inherited member 'DbContext.OnConfiguring(DbContextOptionsBuilder)'. To make the cur
rent member override that implementation, add the override keyword. Otherwise add the new keyword.
C:\Users\Administrator\Desktop\test7\src\test7\Startup.cs(69,30): warning CS0168: The variable 'ex' is declared but never used
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest def
inition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
C:\Users\Administrator\Desktop\test7\src\test7\project.json(21,54): warning NU1012: Dependency conflict. Microsoft.EntityFrameworkCore.SqlServer.Design 1.1.0 expected Microsoft.EntityFrameworkCore.SqlServer >= 1.1.0 but received 1.0.1 C:\Users\Administrator\Desktop\test7\src\test7\Modles\FirstAppDemoDbContext.cs(14,32):
warning CS0114: 'FirstAppDemoDbContext.OnConfiguring(DbContextOptionsBuilder)' hides inherited member 'DbContext.OnConfiguring(DbContextOptionsBuilder)'. To make the cur rent member override that implementation, add the override keyword. Otherwise add the
new keyword.
C:\Users\Administrator\Desktop\test7\src\test7\Startup.cs(69,30): warning CS0168: The variable 'ex' is declared but never used
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest def
inition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
C:\Users\Administrator\Desktop\test7\src\test7\Modles\FirstAppDemoDbContext.cs(14,32): warning CS0114: 'FirstAppDemoDbContext.OnConfiguring(DbContextOptionsBuilder)' hides inherited member 'DbContext.OnConfiguring(DbContextOptionsBuilder)'. To make the current
member override that implementation, add the override keyword. Otherwise add the new keyword. C:\Users\Administrator\Desktop\test7\src\test7\Startup.cs(69,30): warning CS0168: The variable 'ex' is declared but never used
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest def
inition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
C:\Users\Administrator\Desktop\test7\src\test7\Modles\FirstAppDemoDbContext.cs(14,32): warning CS0114: 'FirstAppDemoDbContext.OnConfiguring(DbContextOptionsBuilder)' hides inherited member 'DbContext.OnConfiguring(DbContextOptionsBuilder)'. To make the current
member override that implementation, add the override keyword. Otherwise add the new keyword. C:\Users\Administrator\Desktop\test7\src\test7\Startup.cs(69,30): warning CS0168: The variable 'ex' is declared but never used
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest def
inition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
C:\Users\Administrator\Desktop\test7\src\test7\Startup.cs(69,30): warning CS0168: The variable 'ex' is declared but never used Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest def inition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition
does not match the assembly reference. (Exception from HRESULT: 0x80131040) at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition
does not match the assembly reference. (Exception from HRESULT: 0x80131040) at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
之前上面看到的错误信息,有看到包名就进行安装下
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
System.InvalidOperationException: The following file(s) already exist in directory C:\Users\Administrator\Desktop\test7\src\test7\Modles: Employee.cs. Use the Force flag to overwrite these files.
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator.CheckOutputFiles(String outputPath, String dbContextClassName, IModel metadataModel, Boolean overwriteFiles)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator.GenerateAsync(ReverseEngineeringConfiguration configuration, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContextAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean
overwriteFiles, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.<ScaffoldContextImpl>d__22.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass4_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
The following file(s) already exist in directory C:\Users\Administrator\Desktop\test7\src\test7\Modles: Employee.cs. Use the Force flag to overwrite these files.
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
System.InvalidOperationException: The following file(s) already exist in directory C:\Users\Administrator\Desktop\test7\src\test7\Modles: Employee.cs. Use the Force flag to overwrite these files.
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator.CheckOutputFiles(String outputPath, String dbContextClassName, IModel metadataModel, Boolean overwriteFiles)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator.GenerateAsync(ReverseEngineeringConfiguration configuration, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContextAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean
overwriteFiles, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.<ScaffoldContextImpl>d__22.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass4_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
The following file(s) already exist in directory C:\Users\Administrator\Desktop\test7\src\test7\Modles: Employee.cs. Use the Force flag to overwrite these files.
如上说的问题是当前数据库已经存在model里面的类的表了,所以我就改了下数据库里的表的名称,如下就执行成功了
PM> Scaffold-DbContext "Data Source=.;Initial Catalog=test;User ID=sa;Password=sa1234" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modles
PM>
如果对ASP.NET Core包进行升级的话,版本从1.0至1.1,或其他的包进行了更新之后报错
Scaffold-DbContext : The term 'Scaffold-DbContext' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path
was included, verify that th
e path is correct and try again.
At line:1 char:1
+ Scaffold-DbContext "Data Source=.;Initial Catalog=testData;User ID=sa;Passw ...
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Scaffold-DbContext:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
这样就对“Microsoft.EntityFrameCore”相关的包进行更新下就可以了
如果提示连接数据库语句的问题,看看是不是有安装多个sqlserver版本的数据库,进行区别下就可以了。
如果有找到文档说是需要升级下"Microsoft.EntityFrameworkCore.Tools.DotNet":"1.0.0-preview3-final",安装这个包的时候就会提示此包不支持当前的nuget,这个是在vs2017下应该可以,这个是个人猜测和看文档说的,没有具体实践。
相关文章推荐
- 错误解决:Unable to add module to the current project as it is not of package
- php 使用 Excel/reader.php, 导入excel到数据库 ,解决The file is not readable。。
- 执行 maven 命令 报错Unable to add module to the current project as it is not of packaging type 'pom'
- 错误整理:Unable to add module to the current project as it is not of packaging type 'pom'
- AS.NET2.0 用户控件错误!!The base class includes the field 'MyControl_1', but its type (MyControl) is not compatible with the type of control (ASP.MyControl_ascx).
- 使用MagicAJax的AjaxPanel时有时会弹出"Using the AjaxCallHelper write methods outside of an AjaxCall is not allowed."
- AS升级3.1 编译报错:The SourceSet 'instrumentTest' is not recognized by the Android Gradle Plugin.
- eclipse ERROR: Unable to add module to the current project as it is not of ...
- Unable to add module to the current project as it is not of packaging type 'pom'
- SourceSafe问题:“The filename selected is not recognized as legal. Please select another file or rename the selected file.”异常
- The Excel Connection Manager is not supported in the 64-bit version of SSIS, as no OLE DB provider i
- Execution error: \'the function name is not a recognized built-in function name\'
- "name.bat" is not a recognized as an internal or external command,operable program or batch file
- Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP
- Mac使用Python Matplotlib报错:Python is not installed as a framework. The Mac OS X backend will not
- Execution error: \'the function name is not a recognized built-in function name\'
- RabbitMQ>Erlang machine stopped instantly (distribution name conflict?). The service is not restarted as OnFail is set to ignore.-报错解决方案 原来是NNND。。。
- Unable to add module to the current project as it is not of packaging type 'pom' 问题解决
- The Excel Connection Manager is not supported in the 64-bit version of SSIS, as no OLE DB provider i 推荐
- Item5: Explicitly disallow the use of compiler-generated functions you do not want--若不想使用编译器自动生成的函数,就该明确拒绝