.NET Core – Modularity ”; Previous Next It is another consideration of .NET Core to build and implement application that is modular. Instead of installing the entire .NET Framework, your application can now just install what is required. Let us go to the visual studio and see the modularity. Here is our simple .NET Core application, in Solution Explorer. Let us expand References and you will see reference to .NETCoreApp Inside .NETCoreApp, you will see package reference to NuGet; let us expand it. You will see the whole series of NuGet Package references. If you have worked in .NET Framework, then many of these namespaces will look familiar, because you are used to it by using in .NET Framework. .NET Framework is split into many different pieces and re-implemented with CoreFx; these pieces are further distributed as individual packages. Now if you expand the NETStandard.Library, you will see addition references. You will even notice System.Console which we are using in this application. Now you don’t have to bring in everything inside the .NET Framework, but just bring in what you need for your application. There are some other benefits as well; for example, these modules can be updated individually if desired. Modularity leads to performance benefits and your application can run faster, especially ASP.NET Core application. Print Page Previous Next Advertisements ”;
Category: dotnet Core
.NET Core – Code Execution
.NET Core – Code Execution ”; Previous Next In this chapter, we will understand the execution process of .NET Core and compare it with the .NET Framework. The managed execution process includes the following steps. Choosing a compiler Compiling your code to MSIL Compiling MSIL to native code Running code Choosing a Compiler It is a multi-language execution environment, the runtime supports a wide variety of data types and language features. To obtain the benefits provided by the common language runtime, you must use one or more language compilers that target the runtime. Compiling your code to MSIL Compiling translates your source code into Microsoft Intermediate Language (MSIL) and generates the required metadata. Metadata describes the types in your code, including the definition of each type, the signatures of each type”s members, the members that your code references, and other data that the runtime uses at execution time. The runtime locates and extracts the metadata from the file as well as from framework class libraries (FCL) as needed during execution. Compiling MSIL to Native Code At execution time, a just-in-time (JIT) compiler translates the MSIL into native code. During this compilation, code must pass a verification process that examines the MSIL and metadata to find out whether the code can be determined to be type safe. Running Code The common language runtime provides the infrastructure that enables the execution to take place and services that can be used during execution. During execution, managed code receives services such as garbage collection, security, interoperability with unmanaged code, cross-language debugging support, and enhanced deployment and versioning support. .NET Core Code Execution Process Now let’s relate how code executes with .NET Core as compared to .NET Framework. In .NET Core there are many replacements of these components that are the part of the .NET Framework. In .NET Core now we have a new series of compilers, like we have Roslyn for C# and VB. You can also make use of the new F# 4.1 compiler if you want to use F# with .NET Core. Actually these tools are different and we can use Roslyn with .NET Framework as well if we are using C# 6 or later, because C# compiler can only support up to C# 5. In .NET Core, we don’t have a framework class libraries (FCL), so a different set of libraries are used and we now have CoreFx. CoreFx is the reimplementation of the class libraries for .NET Core. We also have a new run time with .NET Core known as CoreCLR and leverages a JIT Compiler. Now the question is why do we have the reimplementation of all these components that we already have in .NET framework. So the answer is the same as why Microsoft implemented .NET Core. Print Page Previous Next Advertisements ”;
.NET Core – Project Files
.NET Core – Project Files ”; Previous Next In this chapter, we will discuss .NET Core project files and how you can add existing files in your project. Let us understand a simple example in which we have some files which are already created; we have to add these files in our FirstApp project. Here is the implementation of the Student.cs file using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace FirstApp { public class Student { public int ID { get; set; } public string LastName { get; set; } public string FirstMidName { get; set; } public DateTime EnrollmentDate { get; set; } } } Here is the implementation of the Course.cs file. using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace FirstApp { public class Course { public int CourseID { get; set; } public string Title { get; set; } public int Credits { get; set; } } } Let us now save these three files in your disk and the source folder of your project. Now if you are familiar with .NET and this one was a traditional .NET framework console application, it is important to understand how to add these files in your project in Visual Studio. You first need to drag the files to the solution explorer to copy them in your project folder, because your project needs reference to these files. One of the benefits of .NET Core is the approach taken with the project file (project.json); we can just drop files into the root of our project and then these will be automatically included in our project. We don’t have to manually reference files like we did in the past for traditional .NET Framework application in Visual Studio. Let us now open the root of your project. Let us now copy all of the three files into the root of your project. You can now see all the files copied to the root folder. Let us now go to Visual Studio; you will receive the following dialog box. Click Yes to All to reload your project. You will now that files are automatically included in your project. Print Page Previous Next Advertisements ”;
.NET Core – Getting Started
.NET Core – Getting Started ”; Previous Next Visual Studio 2015 provides a full-featured development environment for developing .NET Core applications. In this chapter, we will be creating a new project inside Visual Studio. Once you have installed the Visual Studio 2015 tooling, you can start building a new .NET Core Application. In the New Project dialog box, in the Templates list, expand the Visual C# node and select .NET Core and you should see the following three new project templates Class Library (.NET Core) Console Application (.NET Core) ASP.NET Core Web Application (.NET Core) In the middle pane on the New Project dialog box, select Console Application (.NET Core) and name it “FirstApp”, then click OK. Visual Studio will open the newly created project, and you will see in the Solution Explorer window all of the files that are in this project. To test that .NET core console application is working, let us add the following line. using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace FirstApp { public class Program { public static void Main(string[] args) { Console.WriteLine(“Hello guys, welcome to .NET Core world!”); } } } Now, run the application. You should see the following output. Print Page Previous Next Advertisements ”;
.NET Core – Environment Setup ”; Previous Next In this chapter, we will discuss the Environment Setup of .NET Core. It is a significant redesign of the .NET Framework. To use .NET Core in your application, there are two versions you can use − Visual Studio 2015 Visual Studio 2017 RC Visual Studio 2015 To use Visual Studio 2015, you must have installed the following − Microsoft Visual Studio 2015 Update 3 Microsoft .NET Core 1.0.1 – VS 2015 Tooling Preview 2 Microsoft provides a free version of visual studio which also contains the SQL Server and can be downloaded from https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx and Microsoft .NET Core 1.0.1 – VS 2015 Tooling Preview 2 can be downloaded from https://www.visualstudio.com/downloads/ You can also follow the installation guidelines on the following Url https://www.microsoft.com/net/core/#windowsvs2017 Installation of Visual Studio 2015 Follow these steps to install Visual Studio 2015 − Step 1 − Once the downloading completes, then run the installer. The following dialog box will be displayed. Step 2 − Click Install to start the installation process. Step 3 − Once the installation completes, you will see the following dialog box. Step 4 − Close this dialog and restart your computer if required. Step 5 − Open Visual Studio from the Start Menu; you will receive the following dialog box. It may take a few minutes to load and finally be used for the first time. Step 6 − Once it is loaded, you will see the following screen. Step 7 − Once Visual Studio installation is finished, then close Visual Studio and launch Microsoft .NET Core – VS 2015 Tooling Preview 2. Step 8 − Check the checkbox and click Install. Step 9 − Once the installation completes, you will see the following dialog box. You are now ready to start your application using .NET Core. Visual Studio 2017 In this tutorial, we will be using Visual Studio 2015, but if you want to use Visual Studio 2017, an experimental release of .NET Core tools for Visual Studio is included in Visual Studio 2017 RC and you can see the installation guidelines here https://www.microsoft.com/net/core/#windowsvs2017 Print Page Previous Next Advertisements ”;