/ dotnet

Developing with .NET Core on macOS and Linux

We've been working on a C# API Client over at Clarifai that targets the .NET Standard. .NET Core is a cross platform implementation of this standard. It's definitely confusing for the uninitiated but I found this post cleared the fog.

I started out by installing Visual Studio for Mac as an all-in-one package of the SDK and IDE and was not satisfied. Visual Studio for Mac is basically Xamarin Studio and the support for anything other than building Xamarin Apps isn't the best. The SDK gets installed under /usr/local/share with gross path helpers under /etc/paths.d/.

The version available in Homebrew (cask) is the same package install so that was out.

After much trial and error (and uninstall scripts) I've landed on something I'm happy with.

Install .NET Core SDK

The dotnet-install script will handle the job of installing the SDK. It doesn't follow standard Unix placement (under /usr/local) so I've installed it to /opt/dotnet.

sudo mkdir -p /opt/dotnet
# staff group is specific to macOS - Linux will be different
sudo chown -R $(whoami):staff /opt/dotnet
curl -o dotnet-install.sh https://dot.net/v1/dotnet-install.sh
chmod +x dotnet-install.sh
# Install from the 2.0 channel
./dotnet-install.sh -c 2.0 -i /opt/dotnet
# Symlink the binary
ln -s /opt/dotnet/dotnet /usr/local/bin

IDE

I'm a big Vim user but when it comes to writing Java (and now C#) I reach right for an IDE. The autocompletion and build features are what sell me.

I'd recommend having a go at Visual Studio Code with the C# extension (which it should prompt you to install after you open a C# file). I also use the Vim extension for key bindings. It is a very lightweight editor that still has the autocompletion and build toolset you need.

Another option is Jetbrains Rider for a full-featured IDE experience (though not free). I use IntelliJ IDEA so it felt right at home. Rider is definitely the best option if it's obtainable.

Wrap Up

That should be all you need to get started. Removal is as easy as rm -rf /opt/dotnet /usr/local/bin/dotnet.

Open up your terminal and type dotnet new to see a list of supported project templates.

Happy hacking!