Hi there, my name is Hallam Webber and today I want to show you how to install
.NET core and visual studio code on a mac.
The Cloud Academy C# programming learning path starts with the introduction to C# course where
I show you how to set up a development environment on Windows and ubuntu.
Having demonstrated this process on the first and third most popular desktop operating systems,
it's only proper to include the second macOS. .NET core is a cross-platform development and
runtime environment and C# is a fully featured object-oriented language.
.NET core and C# have a large user base and extensive libraries and their functionality
is constantly evolving and expanding with the considerable resource of Microsoft behind it.
First off, let's download and install the .NET 5.0 sdk software development kit
from dotnet.microsoft.com/download. I'll grab the macOS x64 sdk installer that includes
runtime software libraries for .NET5 and asp.net core. Once that's downloaded, we can install it
like any other software package by clicking on it and following the installer wizard.
I'll enter my password to authorize the installation
We can verify the installation by opening a terminal window
and typing the .NET list sdks command which returns the version and the installation location.
Next, we'll install visual studio code by going to
code.visualstudio.com and downloading the universal stable build.
Once downloaded i'll open VS code and install the C# language support extension.
Click on the extension's icon in the left-hand vertical toolbar
and search for C# for Visual Studio code. When you find it, click the blue "Install" button. I know
dark themes are popular but i'm not a fan so i'll set the color theme to Visual Studio 2019 lite.
Now that we've set up the .NET core and VS code let's create a simple boilerplate
console application with the .NET command line interface. Before making the app, I'll create
a directory structure for my C# projects, so that's projects, csharp and hellomars.
Within the hellomars directory, I'll run the .NET new command for a console application
with the o parameter for the app name as I did in both Windows and ubuntu.
When I run an ls command we can see the hellomars project directory gets created.
Now I can open the project and vs code with the code dot command except I can't as the message
says the command code is unknown. I can make macOS aware of the code command through vs code.
I'll shut down the terminal window and open up vs code,
show the command palette by pressing the f1 key or shift + command + p and start typing shell
in the search box until you see shell command install code command in path then select it.
Enter your password when prompted to install the code command. Now that's done,
we can go back to the hellomars project directory in the terminal and type code dot
which opens vs code with our C# project. As this is the first time running a dot-net
c-sharp project supporting language libraries are downloaded and installed.
When you open a C# project vs code or rather the C# extension prompts
you to set up all the libraries and assets needed to build and debug the application.
I'll click "Yes" to that. In the top left a new directory gets added called vs code
which contains some configuration files for the project. Let's make a few changes
to the boilerplate console application by changing "Hello World" to "Hello Mars".
The first "Hello World" program was written in 1972 using a language called b the precursor to
c which in turn is the ancestor of most of today's programming languages.
Yes here's a small typo which i'll fix up shortly,
I'll also grab the first argument from the args array and assign it to a string variable called
"myName". I explain args arrays and variables in the first two courses of the C# learning path,
but briefly arrays are collections of data like a list where each item can be accessed
with a numerical index and the first item has the index 0 not 1. "myName" is appended to
the hellomars literal text with a plus operator. I'll open up launch.json from the vs code folder.
launch.json tells vs code what to do when I run a program from within vs code.
As i'm accessing the first value from the args array I need to make sure there is at least one
item in the array or else the program will throw an error. I think Elon is an appropriate name
with that done i'll run the program from within vs code by selecting run without debugging.
There we go! hellomars from Elon, but still with a typo. I'll fix that, save and run again
Okay, cool! Let's run the program from within .NET via the command line. We need to dig down into
bin debug and .NET 5.0 to run .NET with the compiled hellomars.dll
passing an elon as an argument. There we go! If you want to learn C# .NET programming, join
me at Cloud Academy for the C# learning path where I take you from zero to hero. The courses cover
C# programming in Windows, Linux and macOS, where i pay special attention to cross-platform features
offered by .NET core and how to integrate and leverage Azure cloud technology. See you there!