Closed arruw closed 2 years ago
Same here when I try to do a Update-Database
(in Code First)
Project.json
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.EntityFrameworkCore": "1.1.0",
"Microsoft.EntityFrameworkCore.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0",
"NETStandard.Library": "1.6.1",
"MyProject.Data.Entities": "1.0.0-*",
"System.Data.Common": "4.3.0",
"System.Data.SqlClient": "4.3.0",
"System.Runtime": "4.3.0"
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final"
},
"frameworks": {
"netstandard1.5": {
"imports": [
"dnxcore50",
"portable-net451+win8"
]
}
}
}
I also tried with "System.Data.SqlClient": "4.1.0" and "System.Data.SqlClient": "4.1.0.0"
Exception
System.IO.FileNotFoundException: Could not load file or assembly 'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Le fichier sp├®cifi├® est introuvable.
File name: 'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerConnection.CreateDbConnection()
at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value()
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_1.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Could not load file or assembly 'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Le fichier sp├®cifi├® est introuvable.
I solved the problem, I don't know how, but it's working.
Project.json
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.EntityFrameworkCore": "1.1.0",
"Microsoft.EntityFrameworkCore.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0",
"NETStandard.Library": "1.6.1",
"MyProject.Data.Entities": "1.0.0-*",
"System.Data.Common": "4.3.0",
"System.Data.SqlClient": "4.3.0",
"System.Runtime": "4.3.0"
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"portable-net40+sl5+win8+wp8+wpa81",
"portable-net45+win8+wp8+wpa81"
],
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-*"
}
}
}
},
"runtimes": {
"win10-x64": {}
}
}
And I also add this
namespace Core.Data
{
public class TemporaryDbContextFactory : IDbContextFactory<MyContext>
{
public MyContext Create(DbContextFactoryOptions options)
{
var builder = new DbContextOptionsBuilder<MyContext>();
builder.UseSqlServer(@"Server=MyConnextionString;Trusted_Connection=True;");
return new MyContext(); //builder.Options
}
}
}
@matjazmav I spent some time debugging this and it is specific to class libraries. You can workaround it by using one of the workarounds listed at the end of https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet. The least intrusive is to add a console application to your project, that references your class library, and then specify it as the startup project.
I took your project.json for your class library, and then added a stub console app to the solution with the following project.json;
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"ClassLibrary1": "1.0.0",
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
}
},
"frameworks": {
"netcoreapp1.1": {
"imports": "dnxcore50"
}
}
}
This command then works for me, it successfully scaffolds the model into the class library:
PM> Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=AdventureWorks2014;Trusted_Connection=True" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -StartupProject ConsoleApp1
I suspect this is already covered by https://github.com/aspnet/EntityFramework/issues/5320, but will wait to confirm with @bricelam before closing.
@bricelam feel free to close if this is already tracked by #5320
I can confirm this as well, as I just ran through the steps that @rowanmiller mentioned. I was using a class library before and created a console app instead to test this.
A quick note: @constantin-v project.json includes "System.Data.Common", "System.Data.SqlClient", and "System.Runtime" but those packages are not needed. (May be a side effect of his solution).
The following project.json file should resolve this and enable tool commands like 'Scaffold-DbContext' to run:
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0",
"Microsoft.EntityFrameworkCore": "1.1.0",
"Microsoft.EntityFrameworkCore.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"NETStandard.Library": "1.6.1",
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
}
},
"frameworks": {
"netcoreapp1.1": {
"imports": "dnxcore50"
}
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.0.0-preview3-final",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
}
}
Closing as a dupe of #5320
I use this project.json. I think it is enough. I copied some settings from the WebApi project, and it works as well as the WebApi project in my Library project.
{ "dependencies": { "Microsoft.NETCore.App": { "version": "1.0.1", "type": "platform" }, "Microsoft.EntityFrameworkCore": "1.1.0", "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0", "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0", "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final", "NETStandard.Library": "1.6.1" },
"frameworks": { "netcoreapp1.0": { "imports": [ "dotnet5.6", "portable-net45+win8" ] } } }
I were having the same error. Fixed by making it default project ("Set as Startup Project").
I'm having problem with scaffolding
DbContext
. I'm using latest.NET Core 1.1.0 SDK
. I'm following this guide: https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-dbBut when I run following command in Package Manager Console:
Scaffold-DbContext "<connection-string>" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
I get exception.project.json
Exception