Hey, guys, I will be speaking on .net Core via Webinar on 5th March where I will talk about my learning on.NET core and how will it is a revolutionary product to change the market among open source giants. MARK YOUR CALENDER AND BE READY FOR .NET CORE

With everything moving towards open source, Microsoft’s biggest framework “.Net Core” will bring a huge revolution in coming future. To understand more about this framework, on 5th of March (Sunday), there is a webinar conducted by Saillesh Pawar on “Learning .Net Core” followed by practical demo. No registration is required. Anyone can join from anywhere. Details for the […]

via Webinar on “Learning .Net Core” on 5th Mar, 2017 — Mumbai Techie Group

Learning Awesome Open Source.NET Core Deep Down that will blow your mind.

AbstractHey, folks, I have been playing around with.NET Core for 1 month I would and there still a lot to cover. Though considering.NET CORE as a sea which is then further divided to lagoon, lakes, ponds and river in form of ASP.NET MVC, Entity Framework Core, ASP.NET CORE etc. I have no hesitation saying that I have just had few drops of rains over my mind and I felt really good to feel the monsoon coming for the.NET developers where we can see the lots of new features coming to.NET stack cross-platform, with performance benchmark, open source.NET technologies which make the Microsoft open to the world. I am a just normal developer who had no knowledge of open source before as I never heard from colleagues or I would say I was not involved with the community. With .NET being open source and now we have.NET core which is built from scratch with running cross platform, cheap deployment on a a Linux machine which was not possible before (Note*- Windows servers are costly as compared to Linux servers). So let’s get started with digging to the Core.

If you want to get started with Dot Net core with steps for downloading the SDK my honest suggestion is to go to my previous blog as mentioned below

  1. Introduction

So I believe that you have followed each and every step as mentioned on the blog to get start using.NET core and you are happy to run your basic set of “HelloWorld” program which just runs fine on Windows, Linux or Mac. So going forward let talk about how.NET and.NET Core is different from each other.

.NET Core is Nuget based which means all the dependencies are in form of NuGet packages that allows app local deployment. While in.NET framework we have to be a dependent upon.NET framework. Every time the new feature is added in the component of.NET framework Microsoft team has to ship the new framework for the same which results in waiting until a given.NET Framework version is widely adopted. With the help of nuget based approach application deploy the new version without waiting for a .net framework to be widely accepted resulting in the easy upgrade to components.

  1. Command line Tooling:

Command line Tooling gives us command line features to run and create the ASP.NET or.NET CORE application with the help of any Text editor, we don’t need our blown Visual studio to create and publish web applications.

All the compiler, runtime and command line tooling are installed in a single go with a single install of SDK.

Below is some.NET Core related command:

  • Dotnet: Once you download the SDK dotnet command will show you the version and help regarding all the related commands as shown below:



Fig.1. An example of a dotnet version.

  • dotnet new: When you install the SDK the dotnet command line tools is referenced to the path. So in order to create a simple.NET CORE app we can use dotnet new command to scaffold a simple hello world program in (figure 2.)

1

Fig.2. Creating Console Application using command line
using System;
namespace ConsoleApplication
{
 public class Program
 {
 public static void Main(string[] args)
 {
 Console.WriteLine("Hello Saillesh!");
}
 }
}
  • dotnet restore: Restores all the dependency defined in the project.json file
E:\poop>dotnet restore
log : Restoring packages for E:\poop\project.json...
log : Installing runtime.win7.System.Private.Uri 4.3.0.
log : Installing runtime.win7-x64.runtime.native.System.IO.Compression 4.3.0.
log : Installing runtime.win.System.IO.FileSystem 4.3.0.
log : Installing runtime.win.System.Net.Primitives 4.3.0.
log : Installing runtime.win.System.Net.Sockets 4.3.0.
log : Installing runtime.win.Microsoft.Win32.Primitives 4.3.0.
log : Installing runtime.win.System.Console 4.3.0.
log : Installing runtime.win.System.Diagnostics.Debug 4.3.0.
log : Installing runtime.win.System.Runtime.Extensions 4.3.0.
log : Installing runtime.ubuntu.14.04-x64.runtime.native.System.IO.Compression 4.3.0
log : Installing runtime.ubuntu.14.04-x64.runtime.native.System.Net.Http 4.3.0.
log : Installing runtime.any.System.Reflection.Extensions 4.3.0.
log : Installing runtime.ubuntu.14.04-x64.runtime.native.System.Net.Security 4.3.0.
log : Writing lock file to disk. Path: E:\poop\project.lock.json
log : E:\poop\project.json
log : Restore completed in 23336ms.
 

It than creates a project.lock.json which contains final list of dependencies which is relevant to the project.

  • dotnet build: to build your application or compile your application for error checking.

2

  • dotnet run: to run you application when you are done checking or compilling you program.

3

  • dotnet publish: Once you complete your application you deploy them to the web server to be hosted and serve the HTTP requests.

4

Dotnet publish –framework netcoreapp1.1 –output “E:\poopDel\publish” –configuration debug –no-build

So once I create my console application and build the same below are the file I get inside bin-debug folder

Fig.3. Project binaries in .NET Core.

Previously in.NET Framework we used to have our executable file EXE. In .net core, we are not running any exe in order to run our program we simply running dotnet run in a folder that contains the project.json file because of project.json files contain all the instruction and dependencies details for the application. The code of our c# application is compiled into .dll this dll is than loaded by dotnet runtime loader that hosts the dll when we run dotnet run command.

There is no mainline exe for the same. We can create a wrapper exe for frameworks by targeting the runtime as specified below:

Set the runtime in Project.json file and run dotnet restore

"runtimes": {
 "win10-x64": {},
 "win7-x64": {},
 },

And when we build the application run the below command:

dotnet build -r win10-x64

5

This will generate the wrapper exe file which will in turn run via dotnet runtime. We need to ensure that we remove the platform attribute from the project.json file as shown below:

"dependencies": {
 "Microsoft.NETCore.App": {
 "version": "1.1.0"
 } },

This is done because I am not going to use .NET core platform that’s installed, I will use local version.

So here is my Project.json with runtimes which I am referring:

{
 "version": "1.0.0-*",
 "buildOptions": {
 "debugType": "portable",
 "emitEntryPoint": true
 },
 "runtimes": {
 "win7-x64":{},
 "win10-x64":{},
 "osx.10.10-x64": {},
 "ubuntu.14.04-x64": {}
 },
 "dependencies": {},
 "frameworks": {
 "netcoreapp1.1": {
 "dependencies": {
 "Microsoft.NETCore.App": {
 "version": "1.1.0"
 }
 },
 "imports": "dnxcore50"
 }
 }
}

So now once I run the dotnet build command with the respective runtime it will create a folder for the same with respective file. Here we are talking about the context to generate the EXE file so I will target win7-x64.

6

So once our progam gets compiled let’s check our executables.

Fig.4. Wrapper exe generated targetting the specific framework.

Now if I try to run the exe file it will work as it’s used to work with .NET framework. This exe isn’t an app but it’s just a wrapper around dotnet.exe to run it on a click rather running dotnet run.

Fig.5 Example Hello World.

  1. Where is my ASP.NET?

So I have been talking about console application but the majority of our enterprise application are Web based. ASP.NET Core project are console applications which will run the server execution environment and then process our http requests. We will look into the granular level so that we would be aware how actually the things are implmeneted in ASP.NET CORE.

So in order to evolve our console application to web application, I will be using Visual studio code to show this demo so that we will aware of how visual studio code can help us building .NET Core application cross platform (*Note: We can use other IDE as well). But with incremental updates of VS Code, it’s one of the best text editor tools to build web based application easily.

So we will create a new project and open the project in Visual studio code using code . as shown below:

Fig.6. Example Opening .NET core project in VS code.

Once we are done opening the project in Vs Code below screen will appear

\

Fig.7. Setting up Visual studio code task and launch.json

Click on yes and Restore.

Restore will run the dotnet restore command for you and download all the necessary dependency in order to run the program. Once we allow Vs Code do all the manual we were doing earlier on. Now all things will be taken care by VsCode and the respective Extensions.Vs code smart enough to know the kind of project, it determines this is .net core project and create the task and launch.json file for the project to run and build the same easily with the task.


Fig.8.Example VS code creating the tasks for the projec to run.

  • Extensions – Here are the plugins which help us in the development of the application, the Extensions can vary accordingly which will help you to be more productive and help you with easy shortcuts and intellisense just like the Visual studio.

Restoring Packages:

In order to find the extensions go to the left menu bar of the vs code and click on the last menu Extensions as shown in Figure 7.

7

You can download the respective extensions as per your requirement. For basic C# I have installed C#, C# extensions, html extension for creating html pages.

So once we have completed the package restore we should build our program, earlier on we were running dotnet build for building our program, but with installed extension and taks all building and running of the application has been configured with the simple shortcut:

Ctrl+Shift+b for BUILD

F5 for running

Let have a look on compiling the program in Figure 8:

8

In order to run the program, we can simply press f5. So now in order to create our Web application, we need to the web server which will server our request and response the respective result to us.

In ASP.NET we have our old giant IIS web server which has been there since ages and it matured enough to handle traffic websites. But in ASP.NET Core we have a new superpower baby server known as Kestrel.

Kestrel is a light weighted web server for hosting ASP.NET Core web application on any platform. It uses the library the is also used by node.js. I am not a node.js developer but one of my friends gave me a simple demo for running the webserver. I found node.js quiet similar to kestrel server.

So in order to get the web server we need to add the respective dependency in Project.json along with our Http dependency which will help us with Http power as shown in Figure 9:

9

Now we are done with Downloading Dependency we have the web server and configure our webserver and than run it to handle the http Requests.

In order to configure the server we need to add a startupClass

//This namespace will help us build our web application
 using Microsoft.AspNetCore.Builder;
//This namespace will hold our application and host it
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
namespace asp.netCore
{
public class StartUp
{
//this method will be called bu the runtime
public void Configure(IApplicationBuilder app)
{
app.Run(context=>
{
return context.Response.WriteAsync("HellO ASP.NET CORE");
});}}}

Now in program.cs we need to configure our web server and run it.

using System;
using asp.netCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
namespace ConsoleApplication
{
 public class Program
 {
 public static void Main(string[] args)
 {
 var host=new WebHostBuilder() //creating the webHostbuilder instance
 .UseKestrel() //use kestrel webserver to run our application
 .UseStartup() //use startup class contains the startup method
 .Build();//builds the server and host the application
 //run the Web application
 host.Run(); } }}

So now let run our program and see the power of kestrel, I know this might be confusing how all things are working. I will explain all once we are done launching our first asp.net to the browser. We need to first build our program and then run it with F5. I hope our first launch of ASP.NET is successful just like ISRO launches the satellites.

Ready Steady Go

12

We have successfully launched a small web application with simple hello world. I hope this article will be helpful to you to dig into the pipelines of.NET CORE. Keep reading keep sharing.

Shortcuts keys in Visual Studio:

This blog is specifically about Shortcuts keys in Visual Studio. In my starting days as a developer when I was getting started with visual studio I used to work manually with the mouse but after some experience, I learned how shortcut keys and extensions like Productivity Power tools, Resharper can improvise you productivity and coding skills. I have to spend a lot of time using a mouse and navigating here and there just to perform the respective operation. As we know Visual Studio is the smart IDE which has the capability to run all the functionality with the keyboard you don’t need to use your mouse to the work. The blog will focus o

n how to learn the productive shortcuts which will help us during our development cycle and amaze your fellow colleague. Share the learning, I will be updating this article as much as I can with lots of features.

  1. Text Navigation:

In line number 13 if I want to navigate to right side words, I will try using right arrow and traverse through each character. Let’s see what happens when I press ctrl key along with right and left arrow. You will see we are able to traverse one word at a time which is quite faster as compared to traversing through each character to reach to the desired word.

pic1

If we want to go to the end of the line and select the text we can use the Shift+ End Key and vice versa for Home.

2.0 Going to end or Starting off the page:

What if our code is too lengthy to be shown on our desktop screen, so in order to scroll position using the keyboard, we should use the down arrow, in another scenario we can use below shortcuts

Shortcuts PageDown and PageUp for Scroll down/ Scroll Up
and Ctrl + End and Ctrl+ Home
for jumping to the end of the file or beginning of the file.

3.0 Text Selection

In order to select the statement of a line, we would use the same shortcut as discussed in 1.0 but we will add one more key to the shortcut in order to Select the text.

We will use Shift+Ctrl+Right or Left arrow for selecting the forward or left word as shown below:

pic2

In order to select the whole one line statement we will simply use Shift+End or Shift+Home as shown below:

pic3

Deleting the whole line:

What if we want to delete the whole line of code. In order to achieve the same, we will just go to the line number and press Ctrl +X or Ctrl +L as shown below:

step5

Deleting One character to the right side: In order delete one character at a time to the right side of the word just use Delete. In case you want to delete to the left side of the word use the Backspace key.

Deleting the word using Backspace or Delete is quite slow so in order to speed up the deletion procedure we will follow some other shortcut for the same as mentioned below:

So as we discussed the selecting of a word using Ctrl key we will use the Ctrl key for deletion as well, just select the word and put the cursor over it press Ctrl key over it and then press Delete as shown below:

step7

Commenting Your Code:

In order to comment your selection, you should just select your multiline code and just press Ctrl+K and Ctrl+C as shown below:

step8

Removing the Comment

In order to remove the comment that you have selected just type Ctrl+K and Ctrl+U.

step9.gif

Bookmarks

I have not heard of bookmarks unless I went through blogs and articles on tips and tricks of Visual studio and found it quite useful. So Bookmarks in visual studio allow us to bookmark the various part of the code to remind yourself that you need to check this code once you are done with some priority changes in other files.

For a while I am working on my another class and want to bookmark my main method so I would just type Ctrl+k+k the bookmark will be attached to the line as mentioned below:


In order to see all the bookmarks, we will press Ctrl+K +W

step11.gif

Rename the bookmark as per your understanding, once you press Ctrl+K+W press Menu keys

step12.gif

 

Creating shortcut in visual studio

In this example,  I am going to show you how to create a shortcut of Package Manager Console in Visual Studio.

  • Go to Options
  • Keyboard

 

1

 

Type PackageManager inside “Show Command” containing as shown below:

2

 

Press the shortcut keys that you want to assign as shown below:

 

3

Click on Assign and you are ready to go.

 

Acknowledgements

Hey, folks, i will be updating this blog as soon as possible till then try these few shortcuts and improvise your productivity. Meanwhile, you can also watch below video tutorial for more shortcuts and tips/ tricks.