Conversation

Your input fuels progress! Share your tips or experiences on prioritizing mental wellness at work. Let's inspire change together!

Join the discussion and share your insights now!

Comments 0

Sharpen your coding skills—try JavaScript challenges on TOOLX now!

advertisement

Basic Guide to .NET Core

.net core


.NET Core is an open-source .NET Framework platform available for Windows, Linux, and Mac OS. As it is a lightweight version of the .NET Framework, not all the libraries of the original framework can be accessed.

The following are the key features of .NET Core:

1. Cross-platform and Container Support:

Most developers prefer to write their business logic code once and reuse it later. This is an easier approach as compared to building different apps to target multiple platforms. Therefore, developers can create an app that will run on Windows, but also on Linux, macOS, and on different architectures, such as x86 and Advanced RISC Machine (ARM). This is ideal in many instances, including desktop applications.

2. High Performance:

.NET Core has relatively higher performance due to the lightweight assemblies and some equally exciting improvements throughout the run-time and the base class libraries.

3. Asynchronous via Async/Await:

C# 5 offered a streamlined method known as async programming capable of leveraging asynchronous support in .NET Framework 4.5 and higher, .NET Core, and Windows Runtime. In this method, the compiler performs complex tasks, which otherwise was done by the developers Further, a logical structure is maintained by the application that is similar to synchronous code. Thus, users are presented with all the benefits of asynchronous programming with little effort.

4. Unified MVC and Web API Frameworks:

MVC controllers and Web APl controllers are now the same. They have now been unified as of MVC 6.0. The .NET Core offers this feature for efficient programming.

5. Multiple Environments and Development Mode:

In IT environments, there are many development environments not supported by the three default environments - Development, Staging, and Production - offered by Microsoft in the ASP.NET Core libraries. NET Core offers other environments ahead of these three, such as Test, DevelopmentExternal, TestExternal, and ProductionExternal.

6. Dependency Injection (DI):

DI is an approach that helps in obtaining loose coupling among objects and their dependencies. Instead of instantiating the dependencies directly or with static references, the objects required by a class to accomplish a task are given to the class in a certain fashion. In simpler words, Dependency Injection is used to make applications independent of their objects or to make classes independent of how their objects are created. Classes declare their dependencies with the help of the constructor.

7. Support for Microservices:

.NET Core supports microservices, which is a type of service-oriented architecture. Microservices are software applications containing small and modular business services. Each service is capable of executing a unique process, being deployed independently, and being developed in various programming applications. .NET Core supports a mix of technologies that can be minimized for each microservice. It can be scaled up as and when new microservices are included.

Note - While it is recommended to run .NET Framework/VS2015 on Windows, .NET Core is preferred in the open source world, such as nodejs, npm, yeoman, and docker.



1. Where and When to Use .NET Core?

.NET Core can be utilized when Docker containers are being employed. Docker is a computer program that carries out operating-system-level virtualization, which is referred to as containerization. Generally, containers and microservices architecture are used in conjunction. Due to its lightweight and modular features, .NET Core operates well with containers. It allows server apps to be set up cross-platform to Docker containers. Though the .NET Framework can be utilized for containers, the image size will be larger.

.NET Core is a perfect fit if there is a requirement for a high-performance and scalable system. Microsoft suggests executing .NET Core along with ASP.NET Core to obtain the best performance and scale. .NET Core is usable if users are executing several .NET versions side-by-side. To set up applications that have dependencies on diverse versions of frameworks in .NET, it is best to employ .NET Core.

.NET Core can be used when the Command Line Interface (CLI) control is required. A few users would prefer to work in lightweight editors and command line control. .NET Core offers a CLI for all supported platforms and it involves minimal installation on production machines.


2. When Not to Use .NET Core

There are a lot of instances when .NET Core can be utilized, however, there are situations in which it is not recommended for use. Though at present, it may not be the best option in some situations, with continued development in the future, it may become suitable for most use cases.

Following are some of the features that are currently not supported in .NET Core:

  • Certain .NET features libraries and extensions such as Entity Framework Core and ASP.NET Web Forms
  • Windows Forms and WPF applications
  • ASP.NET Web Forms
  • Windows Communication Foundation (WCF)
  • Third-party library support
  • Partial support for VB.NET and F#
  • SignalR

Note: Also, some .NET Framework functionalities are still not supported in .NET Core. For instance, Entity Framework Core does not match Entity Framework v6. When there is a requirement for an application to work with Windows Registry, WMI, or other Windows-specific APIs, it will not work.

.NET Core 2.0 offers compatibility between .NET Framework and .NET Core. However, there can still be compatibility issues if the class library employs any .NET Framework APIs that are not supported. The missing .NET Framework APIs open the window for developing and creating new libraries that are not compatible with .NET Core.


3. .NET Framework in Comparison with .NET Core

As .NET Framework can also work with Docker (an open-source platform that enables developers to package applications into containers) and Windows Containers, utilizing it in the following situations possible:

1. When it is already being employed:

Rather than migrating to .NET Core, users can extend the application to continue using it. For instance, a developer can create a new Web service in ASP .NET Core.

2. When utilizing third-party libraries or NuGet packages that are not supported in .NET Core:

Though .NET Core is being utilized extensively, the .NET Framework must be utilized if there is a requirement to work with .NET Framework libraries, which are not compatible. NuGet is the open-source package manager for .NET and other Microsoft development platforms. It contains client tools that are capable of generating and consuming packages.

3. When utilizing technologies that are not yet offered by .NET Core:

If you must work with libraries/technologies that are currently missing in .NET Core, it is recommended that you use the .NET Framework.

4. When .NET Core is not supported by the platform:

.NET Core is unsupported by all Microsoft and third-party platforms, for example, a few services of Azure. However, some problems may arise even with supported services, which come along with the territory. With .NET Core becoming widely popular, users can easily search for tutorials and solutions to circumvent problems.


Following are the situations in which the .NET Framework should not be used:

  • → When several OS platforms are required
  • → When high performance and scalability are required
  • → When .NET Core works
  • → When open source framework is required


4. Porting from .NET Framework to .NET Core

Following are the steps to port an application from .NET Framework to .NET Core:

1. Evaluate Third-party Dependencies:

The Visual Studio tool has an option named Manage Packages, which can be used to install third-party APIs that can be downloaded through the NuGet Package Manager. Following are the package names available under the Nuget Package Manager that aid in porting to .NET Core:

  • netstandard1.0
  • netstandard1.1
  • netstandard1.2
  • netstandard1.3
  • netstandard 1.4
  • netstandard1.5
  • portable-net45-win8
  • portable-win8-wpa8
  • portable-net451-win81


2. Focus on the .NET Standard Library:

As the .NET Standard library is accessible on all .NET run-times, targeting it is an ideal approach to create a cross-platform class library. Several versions are offered across eight platforms. In case a project is targeting an older version, it is not allowed to reference a project targeting a newer version. It is ideal to choose the oldest .NET Standard version to be utilized across all projects.

3. Retarget Projects:

The projects that the users decide to port must be targeted to .NET Framework 4.6.2. This is to make sure that the API alternatives for .NET Framework-specific targets can be utilized for unsupported APls. This can be achieved easily in Visual Studio using the Target Framework command and recompiling the projects.

4. Port Tests Code:

As porting code to .NET Core is an important modification, testing is highly recommended for testing frameworks:

  • xUnit
  • NUnit
  • MSTest

5. Execute the Porting Plan:

The best method suitable for porting the code is based on the way that the framework is structured.

However, splitting the code base into simpler chunks as follows works well:

  • Determine the base of the library, It can be the data models or methods that every other element must utilize.
  • Copy the base onto a new .NET Core project.
  • Perform any modifications required to compile the code.
  • Copy the next layer of code and repeat.


.NET .net core basic guide to .net core .net tutorial what is .net core .net framework features of .net core where and when to use .net core where to use .net when to use .net uses of .net when not to use .net core .net framework in comparison with .net c

advertisement