0% found this document useful (0 votes)
14 views18 pages

NET Core

The document summarizes key differences between .NET Core and .NET Framework. It explains that .NET Core is cross-platform, open source, and optimized for modern workloads like containers and microservices. In contrast, .NET Framework only runs on Windows but supports more legacy features. The document also provides overviews of differences in project files, deployment options, and when to use each framework.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views18 pages

NET Core

The document summarizes key differences between .NET Core and .NET Framework. It explains that .NET Core is cross-platform, open source, and optimized for modern workloads like containers and microservices. In contrast, .NET Framework only runs on Windows but supports more legacy features. The document also provides overviews of differences in project files, deployment options, and when to use each framework.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

TW

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)

 Cross platform: Runs on Windows, macOS, and Linux


operating systems.
 Open source: The .NET Core framework is open source,
using MIT and Apache 2 licenses. .NET Core is a .NET
Foundation project.
 Modern: It implements modern paradigms like
asynchronous programming, no-copy patterns using
structs, and resource governance for containers.
 Performance: Delivers high performance with features
like hardware intrinsics, tiered compilation, and Span<T>.
 Consistent across environments: Runs your code with the
same behavior on multiple operating systems and
Windows macOS Linux architectures, including x64, x86, and ARM.
What is .NET Core?
 Command-line tools: Includes easy-to-use command-line
 An open-source and general-purpose development platform.
tools that can be used for local development and for
 Web and Windows Desktop (Windows Form and WPF) Applications.
 Runs on Windows, macOS, and Linux (x64, x86, ARM32, & ARM64 processors)
continuous integration.
 .NET Core for multiple programming languages (C#, F#, VB.NET etc.).  Flexible deployment: You can include .NET Core in your
 .NET Core for cloud, IoT, client UI, and machine learning. app or install it side-by-side (user-wide or system-wide
 The latest version is .NET Core 3.1. installations). Can be used with Docker containers.
.NET Core & .NET 5

Windows macOS Linux Windows macOS Linux


.NET Core
.NET Framework: side-by-side execution .NET Core: side-by-side execution

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

 WebForms, Web Pages  Angular SPA, API, MVC applications


 WCF Services  gRPC, API, API Gateway, IdentityServer
 ADO.NET Data Service  OData API, GraphQL.
 Workflow (WF)  Not supported.
EF .NET 4.7 EF .NET Core
public class DemoAppDbContext : DbContext public class DemoAppDbContext : DbContext
{ {
public DemoAppDbContext( public DemoAppDbContext(
string name) DbContextOptions<DemoAppDbContext> options)
: base($"name={name}"){} : base(settings){}

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);
} }
} }

 Constructor Parameter takes configkey  Constructor Parameter takes


 DbModelBuilder arguments in OnModelCreating. DbContextOptions<DemoAppDbContext>
 Different methods of DbModelBuilder.  ModelBuilder arguments in OnModleCreating.
 Different methods of ModelBuilder.
PM> Install-Package EntityFramework -Version 6.4.1

PM> Install-Package Microsoft.EntityFrameworkCore -Version 3.1.3

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 add package Newtonsoft.Json  installing Newtonsoft.Json package

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

D:\Priyobrata\Eda\src\Senfu.Eda.Logging>dotnet tool install --g dotnet-counters  installing dotnet-counters performance monitoring


tool

Debug a memory leak in .NET Core


D:\Priyobrata\Eda\src\Senfu.Eda.Logging>dotnet-trace ps
D:\Priyobrata\Eda\src\Senfu.Eda.Logging>dotnet-counters monitor –refresh-interval 1 –p 4807
D:\Priyobrata\Eda\src\Senfu.Eda.Logging>dotnet-dump collect –p 4807
D:\Priyobrata\Eda\src\Senfu.Eda.Logging>dotnet-dump analyze core_20190430_185145
> dumpheap -stat
> dumpheap –mt 00007faddaa50f90
> gcroot –all 00007f6ad09421f8
.NET Core Build Tools and CI
 MSBuild – Same as .NET Framework build process for Continuous Integration (CI).
 CLI commands – Something really new in .NET Core.
 Both MSBuild and CLI commands – mixed and match approach

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.

./dotnet-install.ps1 -Channel 3.1 -InstallDir C:\cli


./dotnet-install.sh --channel 3.1 --install-dir ~/cli
.NET Core : Real Hands-on Example

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;

// 1. Initalize ML.NET environment


var mlContext = new MLContext();

// 2. Load training data


IDataView trainData = mlContext.Data.LoadFromTextFile<ModelInput>( "taxi-fare-train.csv", separatorChar:',’);

// 3. Add data transformations


var dataProcessPipeline = mlContext.Transforms.Categorical
.OneHotEncoding(outputColumnName:"PaymentTypeEncoded", "PaymentType")
.Append(mlContext.Transforms.Concatenate(outputColumnName:"Features",
"PaymentTypeEncoded","PassengerCount","TripTime","TripDistance"));

// 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);

// 6. Evaluate model on test data


IDataView testData = mlContext.Data.LoadFromTextFile<ModelInput>( "taxi-fare-test.csv");
IDataView predictions = model.Transform(testData);
var metrics = mlContext.Regression.Evaluate(predictions,"FareAmount");

// 7. Predict on sample data and print results


var input = new ModelInput { PassengerCount = 1, TripTime = 1150, TripDistance = 4, PaymentType = "CRD" };
var result = mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(model).Predict(input);

Console.WriteLine($"Predicted fare: {result.FareAmount}\n" + $" Model Quality (RSquared): {metrics.RSquared}");


.NET Core : ML.NET Example
PM> Install-Package Microsoft.ML -Version 1.4.0 https://www.codemag.com/Article/1911042/ML.NET-Machine-Learning-for-.NET-Developers

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.

To solve this problem, we will build an ML model that takes as


inputs:
Stochastic Dual Coordinate Ascent (SDCA)
has recently emerged as a state-of-the-art
• vendor ID method for solving large-scale supervised
• rate code learning problems formulated as minimization of
• passenger count convex loss functions.
• trip time
• trip distance
• payment type

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

You might also like