HI WELCOME TO SIRIS
Showing posts with label asp.net core. Show all posts
Showing posts with label asp.net core. Show all posts

ASP.NET Core

Leave a Comment
SP.NET Core is a free, open-source and cloud optimized web framework which can run on Windows, Linux, or Mac. You can say that it is the new version of ASP.NET. The framework is a complete rewrite from scratch in order to make it open source, modular and cross-platform. It was initially launched as ASP.NET 5 but then it was renamed to ASP.NET Core.

ASP.NET Core is a modular framework distributed as NuGet packages. This allows us to include packages that are required in our application.
ASP.NET Core applications run on both, .NET Core and traditional .NET framework (.NET Framework 4.x).

ASP.NET Core is designed to be deployed on cloud as well as on-premises. Developers can now build cloud-based web applications, IoT (Internet of Thing) and mobile backend applications using ASP.NET Core framework which can run on Windows, Linux, and Mac operating systems.
ASP.NET Core is an open source framework supported by Microsoft and the community, so you can also contribute or download the source code from the respective repositories on Github.

ASP.NET Core Version History

VersionRelease Date
ASP.NET Core 2.0August 2017
ASP.NET Core 1.1November 2016
ASP.NET Core 1.0June 2016

.NET Core

Many people are confused between ASP.NET Core and .NET Core. Please note that ASP.NET Core and .NET Core are not the same. They are different, just like ASP.NET and .NET Framework are different.
.NET Core is a fast, lightweight, modular and open source framework for creating web applications and services that run on Windows, Linux and Mac. So, it is a platform on which ASP.NET Core application runs.
.NET Core is named "Core" because it includes core features of the .NET framework. The main objective of .NET Core is to make .NET framework open source, and cross-platform compatible so that it can be used in resource-constrained environments. It includes minimum features that are required to run a basic .NET Core app and other advanced features that can be included as a package from NuGet.
The following figure illustrates the components of .NET Core.

.NET Core Components
As you can see above, .NET Core includes .NET Compiler platform Roslyn, .NET Core runtime CoreCLR, .NET Core framework CoreFX and ASP.NET Core . ASP.NET Core is a part of .NET Core SDK so you don't need to install ASP.NET Core separately. ASP.NET Core and .NET Core is a part of .NET Foundation.
.NET Core comes under MIT or Apache 2 licenses. Visit .NET Core repository on Github to contribute or download the source code.

Why ASP.NET Core?

  • Supports Multiple Platforms: ASP.NET Core applications can run on Windows, Linux, and Mac. So you don't need to build different apps for different platforms using different frameworks.
  • Fast: ASP.NET Core no longer depends on System.Web.dll for browser-server communication. ASP.NET Core allows us to include packages which we need for our application. This reduces the request pipeline and improves the performance and scalability.
  • IoC Container: It includes built-in IoC container for automatic dependency injection which makes it maintainable and testable.
  • Integration with Modern UI Frameworks: It allows you to use and manage modern UI frameworks such as AngularJS, ReactJS, Umber, Bootstrap etc. using Bower (a package manager for the web).
  • Hosting: ASP.NET Core web application can be hosted on multiple platforms with any web server such as IIS, Apache etc. It is not dependent only on IIS as a standard .NET Framework.
  • Code Sharing: It allows you to build a class library which can be used with other .NET frameworks such as .NET Framework 4.x or Mono. Thus a single code based can be shared across frameworks.
  • Side-by-Side App Versioning: ASP.NET Core runs on .NET Core which supports simultaneous running of multiple versions of applications.
  • Smaller Deployment Footprint: ASP.NET Core application runs on .NET Core which is smaller than full .NET Framework. So, the application which uses only a part of .NET CoreFX will have smaller deployment size. This reduces the deployment foot print.
Learn to install ASP.NET Core in the next chapter.

ASP.NET Core Tutorial

Leave a Comment
ASP.NET Core is a new version of ASP.NET by Microsoft. It is an open-source web framework which can be run on Windows, Mac, or Linux.
These tutorials will help you understand ASP.NET Core web application step by step. Tutorials are broken down into chapters, where each chapter contains a number of related topics that are packed with easy to understand explanations and real-world examples.

These tutorials are designed for beginners and professionals who want learn how to build ASP.NET Core web applications step by step.

Prerequisites
Basic knowledge of C#, HTML, Visual Studio, and Object Oriented Programming is required.

So let's get started by clicking Next.

ASP.NET Core Test
Test your ASP.NET Core 2.0 knowledge with a quick test. It includes 20 questions and each question includes 4 options. Select an appropriate answer out of 4 options. There is no time limit for this test.

Getting Started with DotNet CLI

Do you want to develop cross platform apps that will run on Windows, Linux, MacOS then you should for .NET Core, that says “Develop once and deploy on multiple platform”. I have explained about .NET Core in my previous article, you can refer it here To Develop Apps using .NET .Core you can use below methods
  1. Using .NET Command Line Interface (CLI)
  2. Using Visual studio or VS for MAC

  1. Using Visual Studio Code
In this article we will see how to use .NET Command Line Interface (CLI) to create, build, compile and run .NET Core Apps that will deploy on Windows, MacOS and Linux, So let’s get started

.NET CLI Commands



CLI having different commands (that includes Basic command set, Project Modification command set and Advanced command set) that helps to create a base or a foundation, that will support IDE, editors and tools.

Basic commands

new command

This command is used to create New file that file may be solutions file, template or configuration file the syntax of this command is as below
  1. dotnet new <TEMPLATE><Options>
Here dotnet is the keyword and newis the command, Template could be application type like Console app, class library, Unit test project, Razor, MVC, ASP.NET Core file, JSON, NuGet config etc. Go through next example
  1. dotnet new console -o myFirst_CLI_App
In above command console is the application template and-ois the application attribute which is used to generate output in current directory myFirst_CLI_App is the application name

restore Command

This command is used to restores tools and dependencies of the project, basically, this command takes use of NuGet Packages to restore project related tools and dependencies, The syntax of the command is as below
  1. dotnet restore [<ROOT>]
The example, Dotnet restore [Here is the root is the optional path which is project directory, default it is current directory]

build Command

This command is used to build a project with all its dependencies, The syntax is as simple
  1. dotnet build [<PROJECT>]
The example, dotnet build[<PROJECT>, is the path of project that needs to be build, by default it takes current path as project path]

publish Command

As name suggest this command helps to create deployment package, The resultant output is a directory that contains IL (Intermediate Language) files, config files, JSON files, NuGet Packages if exists. The Syntax is
  1. dotnet publish [<PROJECT>]
The example, dotnet publish[<PROJECT> is the path of the project file, default is current directory]

run Command

This command is used to run application, it is very helpful for rapid development from command line, the output of the application is written to the default location that is bin/<configuration>/<target> the syntax is dotnet run, If you want to run any specific project then the syntax would be
  1. dotnet run --project
The example
  1. dotnet run projectprojects/MyProj/MyProj.csproj
in above example projects/MyProj/MyProj.csprojis the project path to run.

test Command

This command is used to execute Unit Test Cases basically it’s a console that support unit test runner, the output of the command is result of each test case that is fail or pass, The syntax is
  1. dotnet test [<PROJECT>]
The example, dotnet test[<Project> is the project path which is optional, default path is current directory]
Some additional Basic commands
S.No.
Command
Syntax/Usage
1
Vtest
dotnet vstest MyProject.dll,It helps to run test from specifi file
2
Pack
dotnet pack, This command packs the code in to packages
3
Migrate
dotnet migrate, This is migration command use to migrate project from Preview 2 to Core SDK 1.0
4
Clean
dotnet clean [<PROJECT>], use to clean project output
5
Sln
dotnet sln <solution name> add <project name>, this command is use to modify (add, remove files in solution) solution file,
6
Help
dotnet help <COMMAND_NAME>, as name suggest it displays help about each command
7
Store
dotnet store -m|--manifest it store the project assembly in package (by default assemblies are not packaged with runtime)

Project Modification Commands

These commands are used to modify project settings like adding and removing of package, references etc.Let’s see them one by one

add package command

This command will add package as a reference in project
  1. dotnet add [<PROJECT>] package <PACKAGE_NAME>
The example, Suppose, I want to add the test.Jsonpackage reference to project, then I can use syntax like
  1. dotnet add package test.Json

add reference command

This command will add reference in project from a project, in short project can be add as a reference in another project
  1. dotnet add [<PROJECT>] reference <PROJECT_REFERENCES>
The example, Suppose, I want to add the app.csproj project in another project then the syntax will be,
  1. dotnet add app.csproj reference test.csproj

remove package command

This command is use to remove package from project
  1. dotnet remove [<PROJECT>] package <PACKAGE_NAME>
The example, Suppose, I want to remove the test.jsonpackage from my project then the syntax will be,
  1. dotnet remove package test.Json
Some additional Basic commands
S.No.
Command
Syntax/Usage
1
remove reference
dotnet remove [<PROJECT>] reference <PROJECT_REFERENCES>,It helps to remove reference of a project from another project
2
list reference
dotnet pack, This command packs the code in to packages

Advanced commands

There are some advanced commands that deals with nuget packages

nuget delete command

This command is use to remove or delete nuget package server
  1. dotnet nuget delete [<PACKAGE_NAME><PACKAGE_VERSION>]
The example, Suppose, I want to remove the AspNetCore.Mvc package from my project then the syntax will be
  1. dotnet nuget delete Microsoft.AspNetCore.Mvc

nuget locals command

This command is use to clear local cache and resources used by NuGet
  1. dotnet nuget locals <CACHE_LOCATION>
The example, Following command will clear all cache directories, temp cache and global temp packages
  1. dotnet nuget locals l all

nuget push command

As name suggest This command is use to push package on server as well as it helps to publish it
  1. dotnet nuget push [<ROOT>]
The example, Following command will push test.pkg to server and publish it
  1. dotnet nuget push foo.nupkg

msbuild command

This command is same like our build menu in Visual Studio, it will build the project with all its dependencies
  1. dotnet msbuild
The example, Following command will build project using release configuration
  1. dotnet msbuild -p:Configuration=Release

.NET CLI Application Templates

There are lot of template exist in C#, F# and VB.NET template. you can install them using CLI commands with different attributes. Some of them are listed below with their CLI commands
Name
Quick Install
.NET Boxed
dotnet new -i "Boxed.Templates::*"
ASP.NET Core SPA Templates
dotnet new -i "Microsoft.AspNetCore.SpaTemplates::*"
Auth0 Templates
dotnet new -i "Auth0.Templates::*"
AWS Lambda .NET Core Templates
dotnet new -i "Amazon.Lambda.Templates::*"
Blazor - Full stack web development with C# and Web Assembly
dotnet new -i Microsoft.AspNetCore.Blazor.Templates::*
Cake.Frosting
dotnet new -i "Cake.Frosting.Template::*"
Carter - Carter is a library that allows Nancy-esque routing for use with ASP.Net Core.
dotnet new -i "CarterTemplate::*"
Cloudscribe
dotnet new -i "cloudscribe.templates::*"
DotVVM - Open source MVVM framework for line of business web applications
dotnet new -i "DotVVM.Templates::*"
For more information you can checkout link .NET Template with CLI commands

Creating and Building An Application Using DotNetCLI

To start building app on .NET Core with CLI, first you need to install .NET SDK. As .NET Core is supporting cross platform compatibility, .NET Core SDK come with cross platform version including Windows (32 and 64 bit), Linux and MacOS. To download your desired installer you can check next link Setup Installer, Now move to Command prompt and type following commands
  1. dotnet new console -o my_first_app
Explanation : With the above new command we are creating console application in my_first_app directory
  1. cd my_first_app
Explanation : Move to directory my_first_app
If you move to my_first_app directory, you will find Program.cs file, it has ‘Hello World’ program written inside it. The code of the program is given below
  1. using System;
  2. namespace my_first_app
  3. {
  4. class Program
  5. {
  6. staticvoidMain(string[] args)
  7. {
  8. Console.WriteLine("Hello World!");
  9. }
  10. }
  11. }
Now put next command
  1. dotnet run
Explanation : It is the basic command used to run project
Output
  1. dotnet run
Hello World!
That’s it. We have successfully completed out first .Net Core program with CLI commands

Dot NET CLI Advantages

  • Rapid development is possible
  • Support crossplat form OS so no need to depend upon only Windows
  • No Need to install Visual Studio
  • Easy compile and run, Just fire runcommand in command prompt and it will do all task for you
Summary
In this article we have learn, If we want to develop a code without visual studio and without windows platform (Linuxor MacOS) then command Line Interface is really good tool. It has all necessary capabilities of Visual Studio starting from New project creation, build, compile, run to publish, It’s so simple that one can easily learn and develop .NET Core app that will crossplatform compatible .NET Core CLI code is available on GitHub