.NET Framework Core Documentation
Introduction to .NET Framework Core
The .NET Framework Core represents a significant evolution of the .NET platform, designed for flexibility, modularity, and cross-platform compatibility. It is a high-performance, open-source framework that enables you to build a wide range of applications, from cloud-native services to desktop applications.
Unlike the traditional .NET Framework, .NET Core is not tied to Windows and can run on Windows, macOS, and Linux. This section provides an overview of its core principles, architecture, and key features.
Key Goals of .NET Core
- Cross-Platform: Run applications on Windows, macOS, and Linux.
- Open-Source: Developed and maintained under the .NET Foundation.
- High Performance: Optimized for speed and efficiency.
- Modularity: A smaller, more focused set of APIs.
- Modern Tooling: Powerful command-line tools (CLI) and IDE integration.
Architectural Overview
.NET Core's architecture is built around a set of foundational components:
- .NET Core Runtime: The execution engine that runs your .NET Core applications. It includes the Common Language Runtime (CLR) and the Base Class Library (BCL).
- .NET Core CLI: A command-line interface for creating, building, running, and publishing .NET Core applications.
- SDK: The Software Development Kit includes the CLI, compilers, and other tools necessary for development.
Core Concepts
Understanding the following concepts is crucial for effective .NET Core development:
- Packages: .NET Core utilizes NuGet packages extensively for modularity and dependency management.
- Project Files (.csproj): Modern .NET projects use a simplified XML-based project file format.
- Target Framework Moniker (TFM): Specifies the version of .NET your application targets (e.g.,
net6.0,net7.0).
A Simple "Hello, World!" Example
Here's a basic example demonstrating how to create a console application in .NET Core:
using System;
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello, .NET Core World!");
}
}
To run this, you would typically use the .NET CLI:
dotnet new console -o HelloWorldApp
cd HelloWorldApp
dotnet run
Runtime Environment
The .NET Core runtime is the foundation upon which your applications execute. It's a sophisticated system responsible for managing code execution, memory, and other critical aspects of application behavior.
Common Language Runtime (CLR)
The CLR is the execution engine for .NET applications. Key features include:
- Just-In-Time (JIT) Compilation: Compiles Intermediate Language (IL) code into native machine code at runtime.
- Garbage Collection: Automatic memory management to prevent memory leaks.
- Type Safety: Enforces type constraints to ensure code reliability.
- Exception Handling: Provides a structured way to handle runtime errors.
Base Class Library (BCL)
The BCL provides a rich set of fundamental classes and types that are essential for .NET development. This includes data structures, file I/O, networking, cryptography, and much more.