I follow ASP.NET Core - New Database to use EF in Asp.net Core under VS 2015. But got below error after installing the packages.
Startup project 'src\CoreMVCWebAPI' is an ASP.NET Core or .NET Core
project for Visual Studio 2015. This version of the Entity Framework
Core Package Manager Console Tools doesn't support these types of
projects.
In the document, it says, it need VS 2017 RC, I am wondering whether it is available under VS 2015, or is there any workaround that I could use EF in Asp.net Core, or Ado.net to retrive Data from SQL DataBase.
PM> Add-Migration MyFirstMigration
Invalid object passed in, ':' or '}' expected. (339): {
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.1",
"type": "platform"
},
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"Microsoft.Extensions.Logging.Console": "1.0.0",
//Dependence for MVC
"Microsoft.AspNetCore.Mvc": "1.1.1",
"Microsoft.AspNetCore.StaticFiles": "1.1.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
"Microsoft.Extensions.Configuration.Json": "1.1.0",
//Dependence for EF
"Microsoft.EntityFrameworkCore":"1.1.0",
"Microsoft.EntityFrameworkCore.InMemory": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools":"1.1.0-preview4-final"
//Dependence for EF with SQL, this is avalible under VS 2017 RC
//"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
//Entity Framework commands to maintain the database
//"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview4-final"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
//used for Razor pages which are compiled at runtime,and the compiler needs access to reference assemblies,
//to make sure it compiles correctly
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Source Code:https://github.com/Edward-Zhou/DotNetCore
You cant use MSBuild (Visual Studio 2017) packages in CSproj (Visual Studio 2015) project. If you will change Microsoft.EntityFrameworkCore.Tools version from 1.1.0-msbuild3-final to for example 1.1.0-preview4-final it should work
Also comments were not allowed in project.json to comply strictly with JSON format. See this announcement github.com/aspnet/Announcements/issues/24 and linked issue for more information/discussion.
You need a reference to EntityFrameWorkCore.Tools.DotNet in the Tools Section as below
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.0.0"
For more info, look at my answer here.
The term "Add-Migration" is not recognized
You must install an earlier version of EF Core, due to compatibility of .NET Core 2.0 with Visual Studio 2015.
I selected EF Core 1.1.5 version and got the message: "Successfully installed 'Microsoft.EntityFrameworkCore.Tools 1.1.5'"
Greetings, Andres!
Related
I have ASP.NET Core Web API project and .Net Core Library project. The Web API has reference to Library project as target : project. Name of the library project is Transformations.
Below is the project.json for both the projects
project.json for Web API
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Transformations": {
"target": "project"
},
"Microsoft.Extensions.DependencyInjection": "1.0.0",
"Serilog.Extensions.Logging": "1.3.0-dev-10125",
"Serilog.Sinks.RollingFile": "3.0.0",
"Serilog.Settings.Configuration": "2.1.0",
"Microsoft.AspNetCore.Diagnostics": "1.0.0"
},
project.json for Library project
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
},
"configurations": {
"Production": {},
"Staging": {}
}
}
On the build server below is the project structure for Api & Transformation projects.
D:\Jenkins\MyJenkinsProject\workspace\src\MySolution
\Api
\Transformation
On the build server I executed the following commands
D:\Jenkins\MyJenkinsProject\workspace\src\MySolution\Api>dotnet restore
and then
D:\Jenkins\MyJenkinsProject\workspace\src\MySolution\Api>dotnet build
I get error
Project Transformations does not have a lock file. Please run
"dotnet restore" to generate a new lock file.
Now if I run the following the following commands in the order, then everything works fine.
D:\Jenkins\MyJenkinsProject\workspace\src\MySolution\Transformation>dotnet restore
D:\Jenkins\MyJenkinsProject\workspace\src\MySolution\Api>dotnet restore
D:\Jenkins\MyJenkinsProject\workspace\src\MySolution\Api>dotnet build
Questions
1>When library is referenced as project in API project why do I need to run dotnet restore separately for library project? Why cant it restores referened project implicitly?
From Zlatko Knezevic:
This behavior is by design. […] If you wish to restore all of the dependencies for all your projects in one go, so to speak, just run dotnet restore at the root of your solution (where you have the global.json file).
i believe you can just do a dotnet build directly. it should automatically do a dotnet restore.
I have a little class library (Core 1), separate so that other apps may also use it, and all those reasons. It has only POCO model classes and a DbContext derivative. Its project file looks as follows:
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"NETStandard.Library": "1.5.0-rc2-24027",
"System.ComponentModel.Annotations": "4.1.0"
},
"frameworks": {
"netstandard1.5": {
"imports": "dnxcore50"
}
}
}
Then I have an ASP.NET Core Web Application (.NET Core) that I wish to use the class library in. Nearly everywhere I look, and I've looked, says to just add the library to the main project's dependencies section of its project file. There it is, right at the top:
"dependencies": {
"WideWorld.Filing": "1.0.0.0",
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
"type": "platform"
},
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0-rc2-final",
I can't even see the library namespace WideWorld.Filing in the main project, where I can, obviously, see its namespace, WideWorld.Office. I am very, very new to Core 1, and have only build monolith web applications before, so please excuse my ignorance if I'm missing something obvious.
If I do a package restore on the main project, I get three warnings in the log (and other stuff that looks harmless):
warn : Detected package downgrade: Microsoft.EntityFrameworkCore.SqlServer from 1.0.0 to 1.0.0-rc2-final
warn : WideWorld.Office (>= 1.0.0) -> WideWorld.Filing (>= 1.0.0) -> Microsoft.EntityFrameworkCore.SqlServer (>= 1.0.0)
warn : WideWorld.Office (>= 1.0.0) -> Microsoft.EntityFrameworkCore.SqlServer (>= 1.0.0-rc2-final)
The issue is that you're mixing packages versions. For example the RTM and RC2 packages are not compatible. You should either target everything as RC2 (which I'd advise against) or take the more preferred approach and upgrade all package references to RTM, targeting version 1.0.0.
More details here:
Note, I have omitted the "import": "dnxcore50"
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"NETStandard.Library": "1.6.0",
"System.ComponentModel.Annotations": "4.1.0"
},
"frameworks": {
"netstandard1.5": { }
}
}
Likewise, in the other project.json do this:
"dependencies": {
"WideWorld.Filing": "1.0.0.0",
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0"
Additional details on packages.
I am creating a new ASP.NET Core project using dotnet 4.5.2 and am trying to add a reference to Microsoft.EntityFrameworkCore.Tools. In my project.json file I have these listed under dependencies:
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
Looking under References, they appear to be successfully loaded. I then added this under tools in project.json:
"Microsoft.EntityFrameworkCore.Tools": {
"imports": [ "portable-net451+win8" ],
"version": "1.0.0-preview2-final"
}
After I added that, when I build the solution I get this build error:
Could not find a part of the path 'C:\Users\(my user name)\.nuget\packages\.tools\Microsoft.EntityFrameworkCore.Tools'
I get the same error if I remove the imports line. What am I doing wrong here?
Just ran into the same issue.
I fixed the issue by installing the tools package again in the package manager console:
Install-Package Microsoft.EntityFrameworkCore.Tools –Pre
Before reinstalling the package was actually missing in the .nuget\packages.tools folder, after reinstalling it was there.
I followed the https://docs.efproject.net/en/latest/platforms/aspnetcore/new-db.html tutorial, but I think I installed the package in the wrong order or initially forgot to reference the EF.tools package in the "tools" section of the project json.
I had this same problem and just solved using the examples from the EF Core setup guide from Microsoft, checking their GitHub code as well, I found this to work for the project.json.
I had to remove the imports from the "frameworks" property, which means no Application Insights for now. Once I did this and built, the folder appeared in the tools folder. Sorry I'm not good at posting code here but here are the important parts, ... elipses used to trim the post of my other things:
"dependencies": {
...
"Microsoft.EntityFrameworkCore": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0",
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
} ...},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.0": {
}...
I had the same issue and had to add the following to my project.json.
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0-preview1-final"
The only difference is that I'm working with the newly release .NET Core 1.1, ASP.NET 1.1 and Entity Framework 1.1.
I had the same issue and tried many things. I found out that Design and Tools need to be the same version but intellisense was not giving me options common to both packages. Then I found this article and tried its code.
https://learn.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet
Using the following code from that article solved the issue for me;
"dependencies": {
"Microsoft.EntityFrameworkCore.Design": {
"type": "build",
"version": "1.0.0-preview2-final"
}
"Microsoft.EntityFrameworkCore.Tools": {
"type": "build",
"version": "1.0.0-preview2-final"
},
},
...
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
},
My problem was I had Microsoft.EntityFrameWorkCore.Tools instead of Microsoft.EntityFramework.Tools, note the lowercase w.
I created a new "ASP.NET Core Web Application (.NET Core)" project in VS2015. It built without any issues, so I thought to give it a test run. However, when starting up, it choked and crashed with the following error:
Exception thrown: 'System.AggregateException' in Microsoft.AspNetCore.Server.Kestrel.dll
The program '[11608] dotnet.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'.
The program '[15048] iisexpress.exe' has exited with code 0 (0x0).
I don't see anything else logged. I tried debugging it, and all I found out was that it broke during the WebHostBuilder.Run() method in Program class. It is part of the framework, so I wasn't able to get much further.
Note that the program runs fine when running via dotnet run command. Only IISExpress does not work.
How should I go about debugging this issue?
The project.json file is below. (It was generated by Visual Studio, I did not change anything.)
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
"type": "platform"
},
"Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview1-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc2-final"
},
"tools": {
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
},
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"gcServer": true
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Update: I created a new project for the Core RTM release, and this time it worked.
The other issue is that you might be running an old version of the framework. Try going to the root (project.json) location of your runnable project and in a Command Prompt type:
dotnet run
I had the same problem as you. For me the solution was to close VS2015, delete the file project.lock.json and then restart VS again. (project.lock.json will be generated automatically)
It looks like the debugger cannot attach to the application. In my case I added a throw new Exception("..."); in the first line of the function public Startup(IHostingEnvironment env) and the application just dies and doesn't break on the unhandled exception as expected.
After project.lock.json was rebuilt the debugger works fine again.
I updated to the RTM release of dotnet core and creating a new project using the new version worked. I guess it must be a bug.
For those bumping into this, I had the same exactly behavior and error message as described in the question.
Apparently there are some terms that can't solely be used as the project name, such as web or app. (I fixed it renaming my project to WebApp)
It was already logged as a bug and the fix will be included in the upcoming releases.
Unfortunately, after the first failed run, a project rename isn't enough to make it work, since the IIS Express config file keeps the old entry.
Just edit the applicationhost.config file located at [PROJECT_ROOT]\.vs\config\ and remove the site element that is named web or app, restart VS and run it.
Hope it helps!
I've got the same error when I run my project (not using IIS).
After some investigation I found out that server url in appsettings.json (which using in Configuration) was already busy. I changed url and it worked well.
Hope it helps somebody!
I had the same error. The solution is found was that my x64 app was set to build as x86
I'm currently using ASP.NET Core MVC RC2 which is suppose to support referencing a full framework library Project from a Core MVC Web Application Project. But I can't seem to make it work.
I have an existing full framework library project that I'd like to use with a new Core MVC Web application project. But when I try to add a reference to the library's project I get an error that says the target framework for it is incompatible with the target framework for the web application.
To try to simplify the problem I created a new Core MVC web application and a new Windows Code Library and tried to add a reference from the web application project to the library's project and got the same error message. I've searched on stack overflow and I did find this question that seemed highly relevent:How to make ASP.NET Core RC2 app build on net46 framework with older third party dependencies but I was unable to use the information there to solve my issue.
Here are the steps to reproduce the issue:
I created a solution with a ".NET Core" "ASP.NET Core Web Application" project based on the "Web Application" template in Visual Studio 2015.
I then added a new "Windows" "Class Library" project to the solution.
So at this point the solution looks like this:
Now, when I try to use visual studio to add reference from the Core MVC Web Application to the Full Framework library I get an error that says that "ExampleLib has a target frameworks that are incompatible with the targets in current project ExampleWebApplicaiton.":
This error seems fairly self explanatory and seems to want me to change the framework that the web application is targeting so that it's the same as the library, which makes perfect sense. The problem is that I can't find documentation on how to do that and intellisense isn't being particularly helpful.
I suspect I need to change one of the following pieces of the project.json file for the web application:
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
"type": "platform"
},
or
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8"
]
}
},
How do I specify .NETFramework Version 4.6 for the Core MVC Web Application instead of .NETCoreApp?
There is a template that allows you to target the full .NET framework - sorry, can't post an image yet, but you can go to:
Templates -> Visual C# -> Web -> ASP.NET Core Web Application (.NET Framework)
Note that you can specify the version of the .NET Framework from the dropdown above (as per usual).
This will change your project.json to:
"frameworks": {
"net461": { }
}
(depending on the framework version that you've selected). You will now be able to add a reference to your class library.
"frameworks": {
"net461": {
"dependencies": {
"ClassLibrary1": {
"target": "project"
}
}
}
}
Following Ron C's steps here's the complete project.json for a web api project I just tested and it worked.
{
"dependencies": {
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"net461": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
],
"frameworkAssemblies": {
"System.Data": "4.0.0.0"
}
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}