NET Core
NET Core
Technical Webcast
.NET Core
How is different from .NET?
April 28, 2020
NextGen, Bangalore
Agenda
• What is .NET Core?
• How is different from .NET Framework?
• How is different from .NET Standard Library?
• What it means to a developer?
• What it means to a build?
• .NET 5.0
.NET Core Why .NET Core? (features)
https://docs.microsoft.com/en-us/dotnet/framework/deployment/in-process-side-by-side-execution
.NET Core can run all versions side-by-side. e.g. 2.0.3 and 2.0.4
will be installed into separate directories. However, it
automatically rolls forward to patch releases, since they contain
security and bug fixes. But it will not automatically run your app
on 2.1.0 if you compiled for 2.0.4 and both 2.1.0 and 2.0.4 are
installed.
You've got an application running on a version of .NET that you do not want to break. At the same time,
you want to run a different application on a different version of .NET that does some things that could
be potentially incompatible with your other application. All in the same single machine.
.NET 4.0 + : Visual Studio Solutions .NET Core: Visual Studio Solutions
Files, Folders and Projects structure are different, not compatible and uninterchangeable.
Irrespective of hosting the web, it is always Program.cs with Startup.cs in .NET core.
Application settings are used of a json file in .NET Core.
The wwwroot folder contains js, css and lib folders.
BCL libraries are completely rewritten for .NET Core and are not compatible assemblies.
Windows Desktop is relatively similar except for BCL libraries. But, you need to check its availabilities.
.NET Core: Visual Studio 2019
.NET 4.0 + : Visual Studio 2019 <Project ToolsVersion="Current"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="Current" <PropertyGroup>
xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <UseIISExpress>true</UseIISExpress>
<PropertyGroup> <Use64BitIISExpress />
<ActiveDebugProfile>IIS Express</ActiveDebugProfile> <IISExpressSSLPort>44337</IISExpressSSLPort>
</PropertyGroup> <IISExpressAnonymousAuthentication />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <IISExpressWindowsAuthentication />
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor> <IISExpressUseClassicPipelineMode />
</PropertyGroup> <UseGlobalApplicationHostFile />
</Project> <LastActiveSolutionConfig>Debug|Any CPU</LastActiveSolutionConfig>
.NET Core .csproj is really not compatible to any older .NET </PropertyGroup>
<ProjectExtensions>
framework .csproj as you can observe here. <VisualStudio>
.NET Core applications can be hosted using Kestrel, IIS, IIS <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
Express or Docker. <WebProjectProperties>
<StartPageUrl></StartPageUrl>
<StartAction>CurrentPage</StartAction>
<AspNetDebugging>True</AspNetDebugging>
<SilverlightDebugging>False</SilverlightDebugging>
<NativeDebugging>False</NativeDebugging>
<SQLDebugging>False</SQLDebugging>
<ExternalProgram></ExternalProgram>
<StartExternalURL></StartExternalURL>
<StartCmdLineArguments></StartCmdLineArguments>
<StartWorkingDirectory></StartWorkingDirectory>
<EnableENC>True</EnableENC>
<AlwaysStartWebServerOnDebug>False</AlwaysStartWebServerOnDebug>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
</Project>
When to Use .NET 4.7 When to Use .NET Core
Worried about the migration to .NET Core. Cross-platforms.
Libraries are unavailable for .NET Core. Microservice architecture.
.NET Core does not support the feature. Deploy in a container or cloud.
Maintaining the same old code base. High performance and scalable systems.
AWS Lambdas or Azure Functions
Side-by-side running
public virtual DbSet<Patient> Patients { get; set; } public virtual DbSet<Patient> Patients { get; set; }
public virtual DbSet<Contact> Contacts { get; set; }
public virtual DbSet<Contact> Contacts { get; set; }
protected override void OnModelCreating(
protected override void OnModelCreating( ModelBuilder modelBuilder)
DbModelBuilder modelBuilder) {
{ modelBuilder.Entity<Patient>()
modelBuilder.Entity<Patient>() .HasMany<Contact>(e => e.Contacts)
.HasMany(e => e.Contacts) .WithOne(e => e.Patient)
.WithRequired(e => e.Patient) .HasForeignKey(e => e.PatientId)
.WillCascadeOnDelete(true); .OnDelete(DeleteBehavior.Cascade);
} }
} }
https://www.softwareblogs.com/Home/Blog/how/DiffEF6andCore/entity-framework-6-entity-framework-core-difference-compare-examples
.NET 4.7.2 to .NET Core (Manual Process)
https://docs.microsoft.com/en-us/dotnet/core/porting/
Retarget all projects you wish to port to target .NET Framework 4.7.2 or higher.
Use the .NET Portability Analyzer to analyze your assemblies and see if they're portable
to .NET Core.
Install the .NET API analyzer into your projects to identify APIs that throw
PlatformNotSupportedException on some platforms and some other potential compatibility
issues.
Install the .NET API analyzer into your projects to identify APIs that throw
PlatformNotSupportedException on some platforms and some other potential compatibility
issues.
Convert all of your packages.config dependencies to the PackageReference format with the
conversion tool in Visual Studio.
Create new projects for .NET Core and copy over source files, or attempt to convert your
existing project file with a tool.
Port your test code.
.NET Core CLI Tools
CLI – Command Line Interface Tool is available in your project path.
Run as Global, Global as a custom location and a Local Tool.
D:\Priyobrata\Eda\src\Senfu.Eda.Logging>dotnet build building Senfu.Eda.Logging.csproj execution
D:\Priyobrata\Eda\src\Senfu.Eda.Logging>dotnet tool install --global dotnet-trace installing dotnet-trace performance analysis utility
tool
D:\Priyobrata\Eda\src\Senfu.Eda.Logging>dotnet tool install --g dotnet-dump installing dotnet-dump dump collection and
analysis utility tool
MSBuild provides you the ability to express your build Using the .NET Core command-line (CLI) tools is
process as tasks and targets, but it comes with the added perhaps simpler, but it requires you to write
complexity of learning MSBuild project file syntax. orchestration logic in a scripting language like bash or
PowerShell.
dotnet-install.ps1 | dotnet-install.sh - Script used to install the .NET Core SDK and the shared runtime.
https://github.com/dotnet-architecture/eShopOnContainers
.NET Core : ML.NET
.NET Core : ML.NET Example
PM> Install-Package Microsoft.ML -Version 1.4.0
using Microsoft.ML;
using Microsoft.ML.Data;
// 4. Set the training algorithm, then create and config the modelBuilder - Selected Trainer (SDCA Regression algorithm)
var trainer = mlContext.Regression.Trainers.Sdca(labelColumnName:"FareAmount", featureColumnName:"Features");
var trainingPipeline = dataProcessPipeline.Append(trainer);
// 5. Train model
var model = trainingPipeline.Fit(trainData);
Problem taxi-fare-train.csv
This problem is centered around predicting the fare of a taxi trip in
New York City. At first glance, it may seem to depend simply on the
distance traveled. However, taxi vendors in New York charge
varying amounts for other factors such as additional passengers,
paying with a credit card instead of cash and so on. This prediction
can be used in application for taxi providers to give users and
drivers an estimate on ride fares.
Solution
and predicts the fare of the ride.
https://github.com/dotnet/machinelearning-samples/tree/master/samples/csharp/getting-started/Regression_TaxiFarePrediction
Thank You.
TW
Technical Webcast
Priyobrata Kshetrimayum
9880759470
[email protected]
www.nextgen.com