Welcome to .NET!
This guide will walk you through the initial steps to start developing with .NET, a free, cross-platform, open-source framework for building all kinds of applications. Whether you're creating web apps, services, desktop applications, or even mobile apps, .NET provides the tools and libraries you need.
With .NET, you can use C#, F#, or Visual Basic to write your code, benefiting from a rich ecosystem and robust performance.
Prerequisites
Before you begin, ensure you have the following:
- A modern operating system: Windows, macOS, or Linux.
- A code editor or Integrated Development Environment (IDE). Visual Studio Code is highly recommended for its excellent .NET support, but Visual Studio (on Windows) or JetBrains Rider are also popular choices.
- Basic understanding of programming concepts.
Installation
The core of .NET development is the .NET SDK (Software Development Kit). This includes the runtime, libraries, and tools needed to build and run .NET applications.
Windows
Step 1: Download the SDK
Visit the official .NET download page: dotnet.microsoft.com/download. Choose the latest stable LTS (Long-Term Support) or STS (Standard-Term Support) version. LTS is recommended for production environments.
Step 2: Run the Installer
Execute the downloaded installer and follow the on-screen instructions. The installer will add the .NET SDK to your system's PATH.
Step 3: Verify Installation
Open Command Prompt or PowerShell and run:
dotnet --version
You should see the installed .NET SDK version printed.
macOS
Step 1: Download the SDK
Go to the .NET download page: dotnet.microsoft.com/download and select the macOS installer.
Step 2: Run the Installer
Open the downloaded `.pkg` file and proceed with the installation.
Step 3: Verify Installation
Open the Terminal application and run:
dotnet --version
The installed version should be displayed.
Linux
Installation on Linux varies slightly by distribution. We'll use the recommended script-based installation.
Step 1: Install using the script
Open your terminal and run the following commands:
wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
chmod +x ./dotnet-install.sh
./dotnet-install.sh --version latest --runtime dotnet
This will install the latest .NET runtime. To install the SDK (which includes the runtime and tools), use:
./dotnet-install.sh --version latest
Step 2: Configure environment variables
Add the .NET installation directory to your PATH. The script will provide instructions, but typically you'll add a line like this to your ~/.bashrc
or ~/.zshrc
:
export PATH=$PATH:$HOME/.dotnet
Then, source your configuration file:
source ~/.bashrc
(or ~/.zshrc
)
Step 3: Verify Installation
Run in the terminal:
dotnet --version
Your First .NET App
Let's create a simple command-line application.
Step 1: Create a project directory
Navigate to where you want to create your project in the terminal and run:
mkdir MyFirstDotNetApp
cd MyFirstDotNetApp
Step 2: Create a new console application
Use the dotnet new
command:
dotnet new console
This command creates several files, including Program.cs
and a project file (e.g., MyFirstDotNetApp.csproj
).
Step 3: Run the application
Execute the application using:
dotnet run
You should see the output:
Hello, World!
You can also inspect the Program.cs
file. It typically contains:
Console.WriteLine("Hello, World!");
Congratulations! You've just created and run your first .NET application.
Next Steps
You're now ready to dive deeper into .NET development!
- Explore C# Fundamentals: Learn about variables, data types, control flow, and object-oriented programming in C#.
- Build Web Applications: Discover ASP.NET Core for building modern web apps and APIs.
- Desktop Development: Investigate WPF or Windows Forms for Windows desktop applications, or .NET MAUI for cross-platform UI.
- Cloud Services: Learn how to build and deploy cloud-native applications with .NET and Azure.
- Official Documentation: Refer to the comprehensive Microsoft .NET documentation for detailed guides and API references.