Tried to use the Entityframework in a .netCore console application with project.json
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-3002702"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}
Unfortunately these packages do not work together:
NU1002 The dependency Remotion.Linq 2.0.2 does not support framework .NETCoreApp,Version=v1.0.
NU1002 The dependency Ix-Async 1.2.5 does not support framework .NETCoreApp,Version=v1.0.
Does someone know how to use the entity framework in .net Core console applications?
Microsoft.EntityFrameworkCore in version 1.0.0-rc2-final uses Remotion.Linq 2.0.2 which (in that version) does not support the netstandard/netcoreapp target framework monikers yet. However it supports the portable class library combination portable-net45+win+wpa81+wp80 which can be imported using the imports statement in the above project.json. The same is true for the deprecated Ix-Async and the portable class library portable-windows8+net45+wp8. Read the rc2 samples of entity framework carefully, they surely import a portable class library target framework moniker.
However, I highly recommend to upgrade to the current .NET Core version (RTM). .NET Core and Entity Framework Core in the above versions are all release candidates and not the final version. RC2 had a go-live license but that will expire (IMHO) like 3 months after the next go-live or final release. Further, Remotion.Linq supports the netstandard then and the Ix-Async was repackaged as System.Interactive.Async and also supports netstandard. Therefore, your problem would vanish.
Related
Im trying to Xamarin and NetStandard and EF Core running.
I got "hello world" running using netstandard.Library 1.3
EF however didnt have a DB to operate on.
So I need to add a migration.
But dotnet ef seems to have a dependency on netstandard.library1.6
i get this error from ef tools when using netstandard1.3
c:\App1>dotnet ef migrations add FirstMigration Project App1
(.NETStandard,Version=v1.3) will be compiled because the version or
bitness of the CLI changed since the last build Compiling App1 for
.NETStandard,Version=v1.3 C:\App1\project.json(10,32): warning NU1007:
Dependency specified was NETStandard.Library >= 1.3.0 but ended up
with NETStandard.Library 1.6.0. Compilation failed.
21 Warning(s)
So if I change projtect.json to have a dependency on netstandard1.6 instead of 1.3
{
"supports": {},
"dependencies": {
"Microsoft.EntityFrameworkCore": "1.1.0",
"Microsoft.EntityFrameworkCore.SQLite": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"Microsoft.NETCore.Platforms": "1.1.0",
"sqlite-net-pcl": "1.3.1",
"Xamarin.Forms": "2.3.4.184-pre1",
**"NETStandard.Library": "1.6.0"**,
"Microsoft.NETCore.Portable.Compatibility": "1.0.1"
},
"frameworks": {
**"netstandard1.6"**: { "imports": "portable-net45+win8+wpa81+wp8" }
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final"
}
}
I get these compile errors
Your project is not referencing the ".NETPlatform,Version=v5.0"
framework. Add a reference to ".NETPlatform,Version=v5.0" in the
"frameworks" section of your project.json, and then re-run NuGet
restore. App1 Error Project App1 is not compatible with uap10.0
(UAP,Version=v10.0) / win10-x64-aot. Project App1 supports:
netstandard1.6 (.NETStandard,Version=v1.6) Error One or more
projects are incompatible with UAP,Version=v10.0 (win10-x86).
is there a way to use netstandard 1.6 in such a project?
I have created a class library project in which I have defined my Models, DbContext, connectionstring and etc. However , I am not able to add migration using the command below
Command
dotnet ef migration add initial
I am getting the error below
Error
Could not invoke this command on the startup project 'Alan.Pois.Data'. This version of the Entity Framework Core .NET Command Line Tools does not support commands on class library projects in ASP.NET Core and .NET Core applications.
Below is the project.json
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.1",
"Microsoft.EntityFrameworkCore.Design": { "version": "1.1.0", "type" : "build" },
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.1.0",
"CommonServiceLocator": "1.3.0"
},
"frameworks": {
"net461": {
}
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools.DotNet": {
"version": "1.1.0-preview4"
}
}
}
IS there anything missing ?
regards,
Alan
I have my context, models and repositories in a class library. My migrations are kept in my web project for the tooling to work (the workaround that I thought was best for the same situation you are experiencing) with a simple configuration call in my EF Core registration. Not sure if this is an option for you...
There are other ways around this, like configuring your class library as an application, and, I realize you'd still need to reference EF packages in two projects (the web app and class library in my case) with the way I'm doing it. I haven't done the "configure your class library as an app" because it just feels like punching something into submission.
Here's EF setup from my Startup.cs:
services.AddDbContext<MyContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("MyConnectionString"), b => b.MigrationsAssembly("MyStartupProject")));
I am trying to learn the basics of ASP.NET Core using this tutorial:
I have created a ASP.NET Core web application
I have upgraded it using instruction from here
Now, I am trying to setup the database migration using dotnet ef migrations add Initial from command prompt within project's folder (where project.json is located):
No executable found matching command "dotnet-ef"
I have changed project.json, so that dotnet-ef works:
"tools": {
...
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview1-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
}
Now, the generation fails with the following error:
The specified framework 'Microsoft.NETCore.App', version
'1.0.0-rc2-3002702' was not found.
- Check application dependencies and target a framework version installed at:
C:\Program Files\dotnet\shared\Microsoft.NETCore.App
- The following versions are installed:
1.0.0
1.0.1
1.1.0
- Alternatively, install the framework version '1.0.0-rc2-3002702'
Ok, it makes sense, because Microsoft.EntityFrameworkCore.Tools 1.0.0-preview1-final relies on the old version mentioned in the error, as found in the project.lock.json file.
I don't want to downgrade, so I put the latest version of Microsoft.EntityFrameworkCore.Tools I could find:
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.1.0-preview4-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
},
Doing this will lead to the same error:
No executable found matching command "dotnet-ef"
How can I make it work in version 1.1?
Other context information that might be useful:
OS: Windows 7 x64
VS: 2015 Community Edition
Other parts from project.json:
"frameworks": {
"netcoreapp1.1": {
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
}
},
"runtimes": {
"win7-x64": {}
},
UPDATE [30/3/2017]
The new package is
Install-Package Microsoft.EntityFrameworkCore.Tools
ORIGINAL
Try adding
"tools": {
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4"
}
Additionally here is a tutorial on setting up .Net Core 1.1.0 with EF Core 1.1.0
https://learn.microsoft.com/en-us/ef/core/get-started/netcore/new-db-sqlite
Grierson's answer is ok, but for future reference I will include the whole process until I made it work:
1) Tools.DotNet already suggested in the accepted answer
"tools": {
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4"
}
Ran the same command and received:
Cannot execute this command because Microsoft.EntityFrameworkCore.Design is not installed. Install the version of that package that matches the installed version of Microsoft.EntityFrameworkCore and try again.
2) Added
//EF Core
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.1.0-preview4-final",
"type": "build"
}
3) Now, the error is:
No parameterless constructor was found on 'ApplicationDbContext'.
Either add a parameterless constructor to 'Application DbContext' or
add an implementation of 'IDbContextFactory' in
the same assembly as 'ApplicationDbC ontext'.
I have chosen to implement the interface. One possible way:
public ApplicationDbContext Create(DbContextFactoryOptions options)
{
var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
builder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=Movies;Trusted_Connection=True;MultipleActiveResultSets=true");
return new ApplicationDbContext(builder.Options);
}
The same error occurs when running dotnet ef migrations add Initial
4) I have added a default constructor for ApplicationDbContext class
Now I can add the migration.
EntityFrameworkCore 1.1.0-preview4-final will work only asp.net core 1.1,if you want to move from core 1.0 to core 1.1,look into https://blogs.msdn.microsoft.com/dotnet/2016/11/16/announcing-net-core-1-1/.
I had the same issue.
that's resolved it for me
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final"
},
You might miss CliToolReference
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
check this
I am trying to get an MVC 6 web application up and running using the .NET 4.6 CLR, but I get the following kind of errors:
The dependency Microsoft.AspNet.Loader.IIS 1.0.0-beta5 in project TestDeployProject does not support framework .NETFramework,Version=v4.6.
project.json:
{
"dependencies": {
"Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
"Microsoft.AspNet.Diagnostics": "1.0.0-beta5",
"Microsoft.Framework.DependencyInjection.Abstractions": "1.0.0-beta5",
"Microsoft.AspNet.Mvc": "6.0.0-beta5"
},
"frameworks": {
"net46": { }
},
}
According to this blog post, the .NET 4.6 target framework does work with ASP.NET 5.
What am I doing wrong?
Unlike most Microsoft.Framework.* projects (like Caching for instance: https://github.com/aspnet/Caching/blob/dev/src/Microsoft.Framework.Caching.Abstractions/project.json#L7), Microsoft.AspNet.* packages only work with the "dnx-flavored" .NET Framework: if you want to use these packages in your own project, remove net46 and add a new dnx46 TFM and it should work.
Note that you'll need a recent DNX runtime version to use dnx46: don't hesitate to migrate to the latest nightly versions.
I am trying to include Google Analytics API package in my MVC 6 application. I've tried to include all the dependencies or to let it install trough NuGet Package Manager. In either case, when i build the solution, I get an error: Error CS0246 The type or namespace name 'Google' could not be found (are you missing a using directive or an assembly reference?) ProjectName.ASP.NET Core 5.0
Any idea what dependencies I need to include for it to build in ASP.Net Core 5.0?
Here is what i have in my project.json file:
"dependencies": {
...
"Microsoft.Net.Http": "2.2.28.0",
"Microsoft.Bcl": "1.1.9.0",
"Microsoft.Bcl.Build": "1.0.21.0",
"Microsoft.Bcl.Async": "1.0.168.0",
"Google.Apis.Analytics.v3": "1.9.0.1100"
},
...
"frameworks": {
"aspnet50": {
"dependencies": {
}
},
"aspnetcore50": {
"dependencies": {
"Newtonsoft.Json": "6.0.8.0"
}
}
},
Similar issue to the one described here: Problems with RavenDB.Client reference in asp.net 5.0 project.json
Adapting my answer from there:
The problem is that you referencing Google.Apis.Analytics.v3 in the top level dependencies node in project.json. That means that those dependencies are applicable to both Desktop CLR (aspnet50) and CoreCLR (aspnetcore50).
When you build an ASPNET 5 project, all configurations are built, not just the "active" one. Mostly sure Google.Apis.Analytics.v3 works only with the Desktop CLR so move it under a dependencies node under that configuration.
"dependencies": {
....
},
"frameworks": {
"aspnet50": {
"dependencies" : {
"Google.Apis.Analytics.v3": "1.9.0.1100"
}
},
"aspnetcore50": {}
}
Then you might have to either use some conditional blocks in your code (#if ASPNET50) or remove CoreCLR all together.
Then you might have to either use some conditional blocks in your code (#if ASPNET50) or remove CoreCLR all together.