Skip to content

Hello World in C# .Net 7 in Windows, Mac, and Linux

Become a developer with our complete learning paths
Become a developer with our complete learning paths

Hello World in C# .Net 7 in Windows, Mac, and Linux

Welcome to the world of programming! If you’re just starting out or looking to try a new development environment, this article is for you. Creating a “Hello World!” application is a classic first step in learning any programming language, and in this article, we’ll show you how to do just that using the popular development tool “Visual Studio”, three different versions of it to be exact: Visual Studio Community Edition on Windows, Visual Studio for MAC on MacOS, and Visual Studio Code on Linux. Whether you’re a Windows, MacOS, or Linux user, we’ve got you covered. In this article, we’ll walk you through the process of setting up your development environment and creating your first Hello World in C# .Net 7 in Windows, Mac, and Linux. Let’s get started!

But first, what even is Visual Studio? To really know what we are getting ourselves into, we might prefer learning a bit about the technology before we get into the development.

What is Visual Studio?

To summarize, Visual Studio is a powerful and comprehensive integrated development environment (IDE) for Windows, Mac, and Linux. As a versatile platform, Visual Studio provides developers with a comprehensive set of tools for building applications across various platforms, including desktop, web, cloud, and mobile.

The IDE’s intuitive user interface, powerful code editor, and integrated debugging and testing tools make creating and maintaining code easy. At the same time, its flexible architecture allows you to extend the platform with a wide range of plugins and extensions to suit your specific needs. Whether you’re a seasoned professional or just starting, Visual Studio has everything you need to create great software.

The platform’s support for Windows, Mac, and Linux operating systems makes it a truly platform-agnostic solution, allowing developers to work on the platform of their choice. With Visual Studio, developers can use an all-in-one solution for building applications across desktop, web, cloud, and mobile platforms without restrictions or licensing costs.

Alright, now that we all know what exactly it is that we are getting ourselves into, let´s get into the next step; wait… do you have it installed already? You might be looking for some aid there as well. Well, for that I can recommend our other article on INSTALLING Visual Studio on all three OS! Go check it out if you need it! Alright, now we can start creating some projects, starting with Windows!

HELLO WORLD! On Windows!

To create a .NET console app project on Windows named “HelloWorld”, you will need to follow these steps using Visual Studio Community 2022:

  • Open Visual Studio 2022.
  • On the start page, select the option to “Create a new project”.

    HELLO WORLD! On Windows!
    HELLO WORLD! On Windows!
  • In the Create a new project page, enter the word “console” in the search box. From the available templates, select the “Console App” template and then choose “Next”.

    HELLO WORLD! On Windows!
    HELLO WORLD! On Windows!
  • If you do not see the .NET templates, you may need to install the required workload. To do this, look for the message “Not finding what you’re looking for?” and select the “Install more tools and features” link. This will open the Visual Studio Installer, where you can ensure that the .NET desktop development workload is installed.
  • In the Configure your new project dialog, enter “HelloWorld” in the Project name box and then select “Next”.

    HELLO WORLD! On Windows!
    HELLO WORLD! On Windows!
  • In the Additional information dialog, select .NET 7 (Standard-term support) and choose “Create”.

    HELLO WORLD! On Windows!
    HELLO WORLD! On Windows!
  • The template will generate a simple application that displays the text “Hello, World!” in the console window.

    HELLO WORLD! On Windows!
    HELLO WORLD! On Windows!
  • To run the program, press Ctrl + F5. A console window will open and display the text “Hello, World!”.

    HELLO WORLD! On Windows!
    HELLO WORLD! On Windows!

Can´t really get easier than that! Luckily Windows makes it really easy to create your projects. Alright! However, what if you were interested in achieving this using a MAC system? For that, you would be using Visual Studio for MAC, so what differs? Let´s check that out!

HELLO WORLD! On MAC!

We will go about the basic differences here compared to the windows project creation, so, let´s check this out! To create a .NET console app project on MAC named “HelloWorld”, you will need to follow these steps using Visual Studio for MAC:

  • To begin, open Visual Studio for Mac on your device. In the start window, you will see an option labeled “New.” Click on it.

    HELLO WORLD! On MAC!
    HELLO WORLD! On MAC!
  • Next, in the New Project dialog, you will need to select the “App” option under the “Web and Console” node. From the templates available, choose the “Console Application” template and then click “Next.”

    HELLO WORLD! On MAC!
    HELLO WORLD! On MAC!
  • In the following dialog, “Configure your new Console Application,” you will see a drop-down labeled “Target Framework.” From the options available, select “.NET 7.0” and then click “Next.”
  • Now, you will need to provide a name for your project. Type “HelloWorld” in the “Project Name” field and then click “Create.”

    HELLO WORLD! On MAC!
    HELLO WORLD! On MAC!
  • The generated template will create a basic “Hello World” application. It will use the Console.WriteLine(String) method to output the message “Hello World!” in the terminal window.
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
  • To run the application, just press the shortcut key combination “⌥⌘↵” (option+command+enter).

 

And that is it, slightly different, but just as easy! With these steps, you should have a .NET console app project on MAC and run a simple “Hello, World!” program using Visual Studio for MAC.
But what about Linux? That can´t be that simple, can it? Let´s find out!

HELLO WORLD! On LINUX!

To create a .NET console app project on Linux (Ubuntu 22.04, to be specific) named “HelloWorld”, you will need to follow these steps using Visual Studio Code:

  • Start by opening Visual Studio Code. Perfect, the easy part is now over; now comes the rest. First, we will need to install C#. Yes, there is an additional step here, but Visual Studio makes this really simple so don´t worry! To achieve this, on the extensions tab, search for “C#”. This will give you a few results. Usually, the first result is what you are looking for. So click on install right there.

    HELLO WORLD! On LINUX!
    HELLO WORLD! On LINUX!
  • Once done, we will meed to get us .Net core installed on our machine so to be able to compile this code. So go to the .Net Core download page and get to the .Net 7 Linux installation instructions and follow along. This may vary over time, so it is advised to go on that page and follow along there. However, we will list the commands we used as of early 2023.
    • First, before we install .NET 7, we have to add the Microsoft package signing key to your list of trusted keys and add the package repository.
      wget https://packages.microsoft.com/config/ubuntu/22.10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
      sudo dpkg -i packages-microsoft-prod.deb
      rm packages-microsoft-prod.deb
    • Then, we can directly go ahead and install the .NET SDK. Make sure to instal .NET 7!
      sudo apt-get update && \
        sudo apt-get install -y dotnet-sdk-7.0
    • After a few minutes, you should have your .NET 7  installation up and running.
  • Now, let´s create the folder we want to create our projects in. We will do so by creating a folder called “visualStudioProjects” in our documents folder.

    HELLO WORLD! On LINUX!
    HELLO WORLD! On LINUX!
  • Now, finally back in Visual Studio Code, we want to open our newly created folder.

    HELLO WORLD! On LINUX!
    HELLO WORLD! On LINUX!
  • Next, we must initialize our new Project. In VSCCode, in the “Terminal” tab we can open a new Terminal.

    HELLO WORLD! On LINUX!
    HELLO WORLD! On LINUX!
  • In that terminal, we need to first run the dotnet new console  command. This will already create a new project with some template code for “Hello World”

    HELLO WORLD! On LINUX!
    HELLO WORLD! On LINUX!
  • Then dotnet restore to install any missing packages
  • And finally, to run it, simply use dotnet run

    HELLO WORLD! On LINUX!
    HELLO WORLD! On LINUX!

And as you can see, “Hello, World!”. A few more steps than with our other options, but not that big of a deal either!

 

Conclusion: Hello World in C# .Net 7 in Windows, Mac, and Linux

Starting your first project in Visual Studio is straightforward, regardless of whether you use Windows, Mac, or Linux. Once you have installed the IDE, you can start building a wide range of applications, from desktop to web to mobile. Whether you are a seasoned developer or just starting out, Visual Studio provides all the tools you need to create great software.

 

If you want to skyrocket your C# career, check out our powerful ASP.NET FULL-STACK WEB DEVELOPMENT COURSE, which also covers test-driven development and C# software architecture.
Lost in coding? Discover our Learning Paths!
Lost in coding? Discover our Learning Paths!
Tired of being just an average developer?
Stop wasting your time and learn coding the right (and easy) way!
Tired of being just an average developer?
Stop wasting your time and learn coding the right (and easy) way!
Enter your email and we will send you the PDF guide:
Enter your email and we will send you the PDF guide