Dot Net For Mac

-->

This tutorial shows how to create and run a .NET Core console application using Visual Studio for Mac.

Supported releases. The following table is a list of currently supported.NET Core releases and the versions of Windows they're supported on. These versions remain supported until either the version of.NET Core reaches end-of-support or the version of Windows reaches end-of-life. Windows 10 versions end-of-service dates are segmented by edition. Supports many.NET project types. Rider supports.NET Framework, the new cross-platform.NET Core, and Mono based projects. This lets you develop a wide range of applications including.NET desktop applications, services and libraries, Unity games, Xamarin apps, ASP.NET, and ASP.NET.

Note

Your feedback is highly valued. There are two ways you can provide feedback to the development team on Visual Studio for Mac:

  • In Visual Studio for Mac, select Help > Report a Problem from the menu or Report a Problem from the Welcome screen, which will open a window for filing a bug report. You can track your feedback in the Developer Community portal.
  • To make a suggestion, select Help > Provide a Suggestion from the menu or Provide a Suggestion from the Welcome screen, which will take you to the Visual Studio for Mac Developer Community webpage.

Prerequisites

  • Visual Studio for Mac version 8.6 or later. Select the option to install .NET Core. Installing Xamarin is optional for .NET Core development. For more information, see the following resources:

    • Tutorial: Install Visual Studio for Mac.
    • Supported macOS versions.
    • .NET Core versions supported by Visual Studio for Mac.

Create the app

Create a .NET Core console app project named 'HelloWorld'.

  1. Start Visual Studio for Mac.

  2. Select New in the start window.

  3. In the New Project dialog, select App under the Web and Console node. Select the Console Application template, and select Next.

  4. In the Target Framework drop-down of the Configure your new Console Application dialog, select .NET Core 3.1, and select Next.

  5. Type 'HelloWorld' for the Project Name, and select Create.

The template creates a simple 'Hello World' application. It calls the Console.WriteLine(String) method to display 'Hello World!' in the terminal window.

The template code defines a class, Program, with a single method, Main, that takes a String array as an argument:

Main is the application entry point, the method that's called automatically by the runtime when it launches the application. Any command-line arguments supplied when the application is launched are available in the args array.

For

Run the app

  1. Press (option+command+enter) to run the app without debugging.

  2. Close the Terminal window.

Enhance the app

Paint Dot Net For Mac

Enhance the application to prompt the user for their name and display it along with the date and time.

  1. In Program.cs, replace the contents of the Main method, which is the line that calls Console.WriteLine, with the following code:

    This code displays a prompt in the console window and waits until the user enters a string followed by the enter key. It stores this string in a variable named name. It also retrieves the value of the DateTime.Now property, which contains the current local time, and assigns it to a variable named date. And it displays these values in the console window. Finally, it displays a prompt in the console window and calls the Console.ReadKey(Boolean) method to wait for user input.

    The n represents a newline character.

    The dollar sign ($) in front of a string lets you put expressions such as variable names in curly braces in the string. The expression value is inserted into the string in place of the expression. This syntax is referred to as interpolated strings.

  2. Press (option+command+enter) to run the app.

  3. Respond to the prompt by entering a name and pressing enter.

  4. Close the terminal.

Next steps

Dot Net Framework 3.5 For Mac

In this tutorial, you created a .NET Core console application. In the next tutorial, you debug the app.

In my previous blog post I have written about running your first dotnet app in a MAC machine. In this post, we will see how we can debug the same app using VSCode Editor. To start debugging your app, we need to have two files configured in the project

Paint Dot Net Alternative For Mac

  1. Launch.json – maintains the debugging session’s launching configurations and other details
  2. Tasks.json – maintains the information about the tasks for the current project. The tasks could be anything from build, test, restore (for this dotnet app). We will see what other types of tasks can be created in detail later.

Step 1 : Create launch.json

In VS Code Editor, click on Debug button on the left side, and then Click on Settings button to create the launch.json file. Refer screen shot below:

Once the launch.json is created, you should see 3 different run configurations

  1. .Net core launch (console) – To start debugging the console app
  2. .Net core launch (web) – To start debugging the web app (asp.net core app)
  3. .Net core attach – Attaching the codebase to already running core app.

For brevity, I have taken only the first configuration which is to debug the console app.

“name”: “.NET Core Launch (console)”,
“type”: “coreclr”,
“request”: “launch”,
“preLaunchTask”: “build”,
“program”: “${workspaceRoot}/bin/Debug/netcoreapp1.0/dotnetDemoApp.dll”,
“args”: [],
“cwd”: “${workspaceRoot}”,
“stopAtEntry”: false
Below are some of the notable configuration entries we need to be aware of

preLaunchTask – this is set to the dotnet build task, which will precede the debugging session (this task will be created in tasks.json file)

program – the name of the program which needs to be debugged, in this case the full path of the current app. The finished launch.json will look like the one in the below screenshot

Now that launch.json is ready, next up is to create the tasks.json which will specify the build task (marked as preLaunchTask) in the launch.json file

Dot Net Machine Learning Library

Step 2: Create tasks.json

Click on the Play button left to the configurations drop down, and VS Code will throw a dialog to create the tasks.json file. The created file will look like the one below

Step 3 : Start debugging

Before starting debugging, make sure to add some breakpoints by clicking to the left of the line number and press Play button. You should start seeing the app getting launched and hitting the breakpoint. Refer screenshot below

Paint Dot Net For Mac

Step 4: Debug more and write more

Dot Net Machine

I have also created a video showcasing these steps in detail as well.