What packages are needed at a minimum for ASP.NET Core MVC (3.1)? - asp.net-core

I created a default (template) ASP.NET Core MVC 3.1 application using Windows 10/Visual Studio 2019. (background: I am looking to re-write/convert an ASP.NET MVC 5 web site to Core 3 MVC).
After creating the default ASP.NET Core MVC solution (which I can compile/run), I noticed in NuGet, that no packages are installed by default. I have the following questions:
1) How is it that the app compiles/runs, even though no packages, not even Core MVC, are shown in Packages installed?
2) For re-writing my app/web site, I will be using MVC, Razor Views, EF Core (using SQL Server, database first approach). When searching in NuGet, there are many related Microsoft packages. What are the minimum packages I must install via NuGet (to get started)?

Have you tried looking at which SDK your project file references when you create an empty ASP.NET Core Web Application?
It's Microsoft.NET.Sdk.Web. This inherits Microsoft.AspNetCore.App, and that metapackage references a whole lot of other packages, amongst others:
Microsoft.AspNetCore.Mvc (>= 2.2.0 && < 2.3.0)
Microsoft.AspNetCore.Mvc.Razor (>= 2.2.0 && < 2.3.0)
Microsoft.EntityFrameworkCore (>= 2.2.6 && < 2.3.0)
So expand the SDKs node under your project, not the Packages node.

In your csproj file, you'll note at the top that the <Project> tag lists an SDK; the SDK handles inclusion of the ASP NET Core supported packages.
From ASP.NET Core Web SDK:
Features enabled by using the Web SDK:
Projects targeting .NET Core 3.0 or later implicitly reference:
The ASP.NET Core shared framework.
Analyzers designed for building ASP.NET Core apps.
From Microsoft.AspNetCore.App for ASP.NET Core:
Projects that target the Microsoft.NET.Sdk.Web SDK implicitly
reference the Microsoft.AspNetCore.App framework.
The ASP.NET Core shared framework:
Doesn't include third-party dependencies.
Includes all supported packages by the ASP.NET Core team.
In order to get started with Entity Framework Core and SQL Server, you can install the specific provider for SQL Server -- Microsoft.EntityFrameworkCore.SqlServer should get you there and cascade the dependencies.
From Installing Entity Framework Core:
To add EF Core to an application, install the NuGet package for the
database provider you want to use.
If you're building an ASP.NET Core application, you don't need to
install the in-memory and SQL Server providers. Those providers are
included in current versions of ASP.NET Core, alongside the EF Core
runtime.

Related

Helper library for ASP.NET Core 5 - NuGet packages not available?

I'm writing a helper library for ASP.NET Core 5 (with .NET 5) and I need some APIs from the package Microsoft.AspNetCore.Server.Kestrel.Core. However, the package is only available in version 2.2 - not version 5.
Is ASP.NET Core no longer distributed via NuGet? And if so, how does one get the APIs with ASP.NET Core 5.
Side note: I found that I could use Microsoft.NET.Sdk.Web as SDK for the project but I'm unsure whether this is a valid/good/correct approach when writing a library.
Is ASP.NET Core no longer distributed via NuGet? And if so, how does one get the APIs with ASP.NET Core 5.
That's correct. The core of ASP.NET Core (no pun intended...) ships with .NET Core >= 3.0 as a shared framework. You can add a single FrameworkReference to your nuget package to pull this in. See https://learn.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-5.0&tabs=visual-studio#migrate-libraries-via-multi-targeting for more information.
Some background can be found here https://github.com/dotnet/aspnetcore/issues/3756

It's very confusing.. I was creating .net core web application and can see .NetFramework with .NetCore support

I was creating .net core web application and can see .NetFramework with .NetCore support. But I didn't choose .Net Standard. I don't understand. Please see the image asp.net core web application
This is Microsoft naming at work here. 😁 There are two dotnet frameworks: the "full" framework, which you selected, and the dotnet core framework.
Before dotnet core and all it's optimized, multiplatform goodness, there was the dotnet framework (refered to as the legacy or full framework). This is the predecessor of dotnet core. This full framework runs only on Windows and the computer it runs on needs the dotnet framework runtime.
Do not worry, the "full" in full framework comes from the transition period between the old dotnet framework and dotnet core. When dotnet core was version 1.0, it did not have all the functionality of today. So some developers called it the full framework (which had everything you needed to run your application) and the newer dotnet core framework which had only the basics.
You can see if you are running the legacy framework if there is the <TargetFramework>netXXX</TargetFramework> present in your solution/project file. The lastest version of the full dotnet framework is 4.8 (net48).
After that it switched to dotnet core 1.0 - 3.1. I'm not entirely sure how that's referenced in the solution/project files.
As a last remark, Microsoft had a great naming idea: the next version of dotnet core is named dotnet 5. They want to get back to the original name with this next version. Do keep in mind that you cannot easily upgrade from dotnet 4.X to dotnet 5. The day to day code looks very much alike, but the underlying engine is completely rewritten.
As far as I know, before .net core 3.0, asp.net core is support on .net framework. This is the reason why you could create .net core 2.1 on the .net framework.
But after 3.0, asp.net core not support .net framework. You could only create it on .net core framework.
More details, you could refer to this article and this github issue.

Using Entity Framework 6 in ASP.NET Core

Let's say I have:
ASP.NET Core stand alone Web API project for .NET Core framework
Class Library with EF6 data model for full .NET framework
The ASP.NET Core project refers to the class library
This architecture proposed here:
https://learn.microsoft.com/en-us/aspnet/core/data/entity-framework-6
The question is: will my standalone application be able to execute on the specified target platform (Win, Linux, Mac runtime) after Release (or Publish), if it's dependency targets to full .NET Framework?
Thanks very much
It will be not possible. The same link you provided confirm that:
To use Entity Framework 6, your project has to compile against .NET Framework, as Entity Framework 6 does not support .NET Core. If you need cross-platform features you will need to upgrade to Entity Framework Core.
You can use ASP.NET Core upon .NET Framework (Not .NET CORE) and EF6 (But not cross-platform). But not ASP.NET Core upon .NET Core and use EF6. You will need to use EF Core for that project.
Disclaimer: I'm the owner of the project Entity Framework Classic
That's not possible directly Entity Framework as #Adailson answered
However, it's possible via EF Classic: http://entityframework-classic.net/
That's an EF6 fork that also supports .NET Core. We plan to integrate a ton of features & bug fix.
A community (FREE) and enterprise version (PAID) is available.
What's EF Classic
Entity Framework Classic is a supported version from the latest EF6 code base. It supports .NET Framework and .NET Core and overcomes some EF limitations by adding tons of must-haves built-in features.

ASP.NET Core self-contained exe

I want my ASP.NET Core Web API to run as a self-contained exe within the .NET framework and not .NET Core Framework. Is that possible? Thanks!
EDIT:
If I add "net451": {} to my frameworks section in project.json,
I get the following exception:
Failed to make the following project runnable: myProject (.NETCoreApp,Version=v1.0) reason: Expected coreclr library not found in package graph. Please try running dotnet restore again.
You can't create a self-contained app which targets .NET Framework >=4.5, because the full .NET Framework isn't modular and its not possible to have more than one version of it installed. Newer versions basically always replace the previous one.
Self-contained apps were one main motivation for .NET Core (together with portability)
You ALWAYS have to install .NET >=4.5 before your app can run. self-contained apps only work with .NET Core because .NET core libraries can be pulled through nuget package.
For .NET 4.6 you can only create portable apps, which is the default mode.

.NET Core is not listed

I wanted to create a new ASP.NET Core app targeting the new .NET Core 1.0.
First, in Visual Studio 2015 Update 3, I don't see .NET Core listed
And this is what I'm seeing in project.json file. Looks like I'm targeing dotnet5.6
Is it safe to assume this is all correct?
And if this is correct, could it possibly be more confusing?
The pulldown has no meaning for .NET Core projects as it doesn't use it. Only what's in project.json matters for .NET Core / .xproj projects.
netcoreapp1.0 target framework moniker (short TFM) is .NET Core project for executables (ASP.NET Web Application or .NET Core Console Application). netstandard1.x (see this matrix for api surface of netstandard TFM) is for class libraries.
The import section just tells nuget to also restore packages which target dotnet5.6 (old TFM for .NET Core Library, which is now replaced with netstandard1.x) and portable-net45-win8, which are also compatible with .NET Core. These allow you to install packages which are compatible but are not yet repackaged for netstandard1.x.