Getting Started with .NET Core
Welcome to the .NET Core getting started guide. This section will walk you through the essential steps to begin developing applications with .NET Core.
1. Prerequisites
Before you begin, ensure you have the following installed on your system:
- .NET Core SDK: Download and install the latest .NET Core SDK from the official Microsoft .NET website.
- Code Editor: We recommend using Visual Studio Code with the C# extension for a streamlined development experience. Other IDEs like Visual Studio (for Windows) or JetBrains Rider are also excellent choices.
2. Creating Your First .NET Core Application
Once the SDK is installed, you can create your first application using the command line.
a. Open your terminal or command prompt.
Navigate to the directory where you want to create your project.
b. Create a new console application.
Run the following command:
dotnet new console -o MyFirstApp
This command does the following:
dotnet new console
: Creates a new project of type 'console'.-o MyFirstApp
: Specifies the output directory for the project. If omitted, the project files will be created in the current directory.
c. Navigate into your project directory.
cd MyFirstApp
d. Run your application.
Execute the following command to build and run your application:
dotnet run
You should see the following output:
Hello, World!
3. Understanding the Project Structure
Your new console application will have a simple structure:
MyFirstApp.csproj
: The project file that contains build information.Program.cs
: The main file where your application's code resides.obj/
: A directory for intermediate build files.bin/
: A directory containing the compiled application.
The Program.cs
file typically contains the following code:
using System;
namespace MyFirstApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
}
Note: The dotnet run
command automatically builds your project if necessary before running it. You can also use dotnet build
to only build the project.
4. Exploring Other Project Types
.NET Core supports a variety of application types. You can create them using the dotnet new
command:
- Web API:
dotnet new webapi -o MyWebApi
- ASP.NET Core MVC:
dotnet new mvc -o MyMvcApp
- Class Library:
dotnet new classlib -o MyLib
You can see a full list of available project templates by running: dotnet new --list
Key takeaway: The dotnet new
command is your primary tool for scaffolding new .NET Core projects of various types.
Next Steps
Now that you've created your first .NET Core application, you can explore more advanced topics: