Swiftorial Logo
Home
Swift Lessons
Tutorials
Learn More
Career
Resources

Introduction to .NET

Setting Up Development Environment

In this tutorial, we will cover the steps to set up your development environment for .NET. We will walk through installing the necessary tools and creating your first .NET application.

1. Install .NET SDK

The .NET SDK (Software Development Kit) is required to develop .NET applications. Follow these steps to install it:

  1. Go to the official .NET download page.
  2. Download the latest version of the .NET SDK for your operating system (Windows, macOS, or Linux).
  3. Follow the installation instructions for your operating system.

Example: Verifying .NET Installation

After installation, open your terminal or command prompt and run the following command to verify the installation:

dotnet --version

You should see the installed version of .NET SDK.

2. Install Visual Studio Code

Visual Studio Code (VS Code) is a lightweight and powerful source code editor that works on Windows, macOS, and Linux. Follow these steps to install it:

  1. Go to the official Visual Studio Code download page.
  2. Download the appropriate version for your operating system.
  3. Follow the installation instructions for your operating system.

Example: Opening a Folder in VS Code

After installation, open VS Code and follow these steps to open a folder:

1. Click on "File" in the menu.
2. Select "Open Folder..."
3. Browse to the folder you want to open and click "Select Folder".

3. Install .NET Extensions for VS Code

To enhance your development experience, install the following extensions in VS Code:

Example: Installing Extensions in VS Code

To install an extension, follow these steps:

1. Click on the Extensions icon in the Activity Bar on the side of the window.
2. In the Extensions view, type the name of the extension you want to install.
3. Click on the "Install" button next to the extension.

4. Create Your First .NET Application

Let's create a simple .NET console application:

  1. Open your terminal or command prompt.
  2. Create a new directory for your application and navigate to it:
  3. mkdir HelloWorld
    cd HelloWorld
  4. Create a new console application using the .NET CLI:
  5. dotnet new console
  6. Open the folder in VS Code:
  7. code .
  8. Open the Program.cs file and replace its contents with the following code:
  9. using System;
    
    namespace HelloWorld
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Hello, World!");
            }
        }
    }
  10. Run the application:
  11. dotnet run

Example: Output of the Application

You should see the following output:

Hello, World!

5. Debugging Your Application

VS Code provides powerful debugging capabilities. Follow these steps to debug your application:

  1. Set a breakpoint by clicking in the gutter to the left of the line numbers in the Program.cs file.
  2. Press F5 or click on the Debug icon in the Activity Bar and then click on "Run and Debug".
  3. Select ".NET Core" as the environment.
  4. VS Code will start the debugger and your application will run. Execution will pause at the breakpoint you set.

Conclusion

In this tutorial, we covered the steps to set up your development environment for .NET, including installing the .NET SDK, Visual Studio Code, and necessary extensions. We also walked through creating and running a simple .NET console application. With your development environment set up, you're ready to start building .NET applications.