C#/.NET on MacOS
Prerequisites
- Homebrew
- or Nix
- Rider (or Visual Studio, Rider is recommended by the school, because it is compatible with Linux, and is accessible during exams)
Introduction
.NET is a framework developed by Microsoft, which allows the development of applications in C#. .NET is available on MacOS, Linux, and Windows. It is the framework used by the school for the first year C# courses at EPITA, supervised by the assistants (ACDC).
Installation
To install .NET, you have several options. You can install Rider, which will propose to install .NET during the first launch, or install it manually using the command line. Let's start by installing Rider.
Rider
Rider is an IDE developed by JetBrains, which is compatible with .NET, C#, and Mono. It is available on MacOS, Linux, and Windows. To install it, simply go to the JetBrains website and download the macOS version.
You can also install Rider through the JetBrains ToolBox, which will allow you to manage all of your JetBrains IDEs from a single application.
If you are a student, you can obtain a free license for all of JetBrains IDEs by logging in with your student email here.
When you launch Rider for the first time, it will offer to install .NET. Accept this and allow the installation to proceed. Take note, it will only offer to install the latest version of .NET, which might not be compatible with certain projects or what the teaching assistants ask for. To install a specific version, you will need to use the command line.
Command line
To install .NET with Homebrew or Nix, simply run the following command:
- Brew
- Nix
brew install dotnet # Installe la dernière version de .NET
brew install dotnet@7 # Installe la version 7 de .NET
nix-env -iA nixpkgs.dotnet-sdk_VERSION # Install a specific version of .NET
# change VERSION with the version you want to install (eg: 5.)
You can search on search.nixos.org
the exact name of the package to install. Be careful to take the package that contains dotnet-sdk
and not dotnet-runtime
.
Manual installation
You can go to the official .NET website to download the desired version of .NET.
Usage
Creating a project
To create a project, click on New Solution
in the Rider home window, then choose Console Application
.
Be careful to choose .NET/.NET Core
and not .NET Framework
.
Adding a NuGet package
In the bottom bar of Rider, you will see a NuGet
tab, click on it to open the NuGet package management window.
You can then search for the desired package and install it.
You can also add a NuGet package by adding the following line to your .csproj
file:
<ItemGroup>
<PackageReference Include="PACKAGE_NAME" Version="VERSION" />
</ItemGroup>