. NET Core 2.0
For a long time. NET Framework has been hacked because it can only run on Windows systems. So Microsoft has rewritten a cross-platform. NET, which is. NET Core. Now. NET core has been updated to 2.0. If you are interested, you can check the official update log. In short, all students who use. NET core are best updated to the latest version, with improvements in performance, API implementation, and command friendliness. Visual Studio 2017 15.3+
Accordingly, Visual Studio 2017 is also updated, please see update log for details, this one has Chinese version, very conscience. If you want to use. NET Core 2.0 in new VS, you will also need to install a separate. NET Core 2.0 SDK, after which the VS will recognize the new. NET Core 2.0 SDK. Entity Framework Core 2.0
Microsoft's ORM Framework entity has also been updated, and this is the official update log. In the entity Framework Core 2.0, I've brought some updates that I think are useful. . NET Standard 2.0 Support
Now the EF Core 2.0 also supports. NET Standard 2.0. This means that in the future we can use a consistent API on a variety of platforms such as the. NET Framework, Mono, Xamarin, UWP, and so on. Improved LINQ translation
For example, the following LINQ is translated into the corresponding like query statement.
var customers = from C into context
. Customers
where EF. Functions.like (C.name, "a%");
Select C;
The corresponding query statement is as follows.
SELECT [C]. [Id], [C]. [Name]
From [Customers] as [c]
WHERE [c].[ Name] Like N ' a% ';
string Interop in native SQL
This is a feature that I think is very practical.
var city = "Redmond";
using (var context = Createcontext ())
{context
. Customers.fromsql ($@ "
select * from
Customers
WHERE city = {city}");
There are some features I did not introduce, directly read the official update log. asp.net Core 2.0
For a detailed update of ASP.net Core 2.0, please see the official blog. Razor Pages
A new technology Razor pages has been introduced in the new version, and it is well applied in some of the more page-oriented scenarios. If MVC is enabled in the project, then razor pages are also automatically enabled.
See the official example, below is a razor pages, which is similar to the common razor syntax of the MVC view page, except that the top part uses the @page instruction to identify this as a separate razor pages.
@page
You can also add functions in razor pages.
@page
@functions {public
string formatdate (DateTime thetime) {return
thetime.tostring ("D");
}
You can also inherit and use Pagemodel to take advantage of the MVVM model. Details can be referred to the official document, no longer repeat here.
In addition to Razor Pages, the new version also updates new project templates, DbContext buffer pools, and application insights monitoring without the need to change code. Please refer to the official documentation for details. upgrade from 1.1 to 2.0
I have also done a asp.net core applet to play, just to take this opportunity to upgrade to 2.0, here reference to the official migration guide. Before migrating, make sure that the. NET Core 2.0 is installed correctly. Update Target Framework
First, upgrade the target framework, which requires modifying the csproj file. If the target frame for the original project is. NET Core, upgrade it to netcoreapp2.0.
<TargetFramework>netcoreapp2.0</TargetFramework>
If the target frame for the original project is the. NET Framework, specify the version that is greater than or equal to the. NET Framework 4.6.1, such as net461.
<TargetFramework>net461</TargetFramework>
Update Project References
It also needs to be modified according to the project's target framework. Here is the dependency package reference in my original project.
<ItemGroup>
<packagereference include= "Microsoft.ApplicationInsights.AspNetCore" version= "2.0.0" >
<packagereference include= "Microsoft.aspnetcore" version= "1.1.1"/>
<packagereference Include= "MICROSOFT.ASPNETCORE.MVC" version= "1.1.2"/> <packagereference include=
" Microsoft.AspNetCore.StaticFiles "version=" 1.1.1 "/>
<packagereference include=" Microsoft.Extensions.Logging.Debug "version=" 1.1.1 "/>
<packagereference include=" Microsoft.VisualStudio.Web.BrowserLink "version=" 1.1.0 "/>
</ItemGroup>
If the target framework is. NET Core, replace these with a single meta package.
<ItemGroup>
<packagereference include= "Microsoft.AspNetCore.All" version= "2.0.0"/>
</ Itemgroup>
If the target framework is a. NET framework, then these dependencies cannot be modified, but all versions should be modified to 2.0.
<ItemGroup> <packagereference include= "Microsoft.aspnetcore" version= "2.0.0"/> <packagereference Include= "Microsoft.AspNetCore.Authentication.Cookies" version= "2.0.0"/> <packagereference include= " Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore "version=" 2.0.0 "/> <packagereference include=" Microsoft.AspNetCore.Identity.EntityFrameworkCore "version=" 2.0.0 "/> <packagereference include=" MICROSOFT.ASPNETCORE.MVC "version=" 2.0.0 "/> <packagereference include=" Microsoft.AspNetCore.Mvc.Razor.ViewCompilation "version=" 2.0.0 "privateassets=" All "/> <packagereference Include= "Microsoft.AspNetCore.StaticFiles" version= "2.0.0"/> <packagereference include= " Microsoft.EntityFrameworkCore.Design "version=" 2.0.0 "privateassets=" All "/> <packagereference include=" Microsoft.EntityFrameworkCore.SqlServer "version=" 2.0.0 "/> <packagereference include=" Microsoft.EntityFrameworkCore.Tools "version=" 2.0.0 "Privateassets= "All"/> <packagereference include= "Microsoft.VisualStudio.Web.BrowserLink" version= "2.0.0"/> < Packagereference include= "Microsoft.VisualStudio.Web.CodeGeneration.Design" version= "2.0.0" privateassets= "All" > </ItemGroup>
Update command line tool version
Update the Version property of all <dotnetclitoolreference/> nodes in the csproj file to 2.0.0, for example, below.
<ItemGroup>
<dotnetclitoolreference include= "Microsoft.EntityFrameworkCore.Tools.DotNet" version= " 2.0.0 "/>
<dotnetclitoolreference include=" Microsoft.Extensions.SecretManager.Tools "version=" 2.0.0 " >
<dotnetclitoolreference include= "Microsoft.VisualStudio.Web.CodeGeneration.Tools" version= "2.0.0" >
</ItemGroup>
Rename Package Target fallback Property
Modify the Packagetargetfallback nodes and values to assettargetfallback nodes and properties.
<packagetargetfallback>$ (packagetargetfallback);p Ortable-net45+win8+wp8+wpa81;</packagetargetfallback >
Here is the modified.
<assettargetfallback>$ (assettargetfallback);p ortable-net45+win8+wp8+wpa81;</assettargetfallback>
update the Main method in Program.cs
The main method can be simplified to the following.
public class program
{public
static void Main (string[] args)
{
buildwebhost (args). Run ();
}
public static Iwebhost Buildwebhost (string[] args) =>
webhost.createdefaultbuilder (args)
. Usestartup<startup> ()
. Build ();
}
Then, if the ASP.net permission/authentication API is used in the project, it needs to be modified accordingly.