Logo

dev-resources.site

for different kinds of informations.

.NET Development Essentials on macOS with VS Code

Published at
12/29/2024
Categories
dotnet
vscode
cli
extensions
Author
ovichowdhury
Categories
4 categories in total
dotnet
open
vscode
open
cli
open
extensions
open
Author
12 person written this
ovichowdhury
open
.NET Development Essentials on macOS with VS Code

.NET 9 continues the tradition of Microsoft's commitment to performance, reliability, and developer productivity. With every iteration, .NET has gained features and optimizations that make it one of the leading platforms for modern application development. But unfortunately the most powerful IDE of .NET development Visual Studio isn't available on macOS.

Microsoft officially announced that they will no longer support Visual Studio for macOS and made VS Code the de-facto standard IDE for cross platform C# development. According to Microsoft official statement -

"While we have retired Visual Studio for Mac, we remain committed to our developers on Mac and .NET MAUI with alternatives like the C# Dev Kit for Visual Studio Code and other extensions you can use to take advantage of our ongoing investments in .NET development."

While VS Code with C# Dev Kit is a great choice but Visual Studio developers may need some guidance to effectively use VS Code with the C# Dev Kit. This blog post aims to provide a comprehensive guide to making .NET development on macOS feel like a native experience.

Install C# Extensions in VS Code

Extensions Image

Here are some VS Code extensions to enhance your C# and .NET development experience.

  1. C# Dev Kit
  2. C# - Base Language Support
  3. IntelliCode for C# Dev Kit

After installing the extensions the command palette of VS Code is supercharged with .NET related commands i.e. Create a New Project, Opening an Existing Solution, etc. So lets inspect the changes with (Command + Shift + P) and type .NET in the command palette.

Command Palette Image

Although the command palette offers a way to manage projects and solutions, using the .NET CLI directly can boost developer productivity.

The Concept of Solution and Project in .NET

In the .NET ecosystem, Solution and Project are foundational organizational concepts used within Visual Studio and other .NET development environments. They help developers manage the structure, dependencies, and workflow of software development.

Project:

A Project in .NET represents a single, self-contained unit of work or a collection of source files, references, and resources. It is essentially the building block of a .NET application. Defined by a .csproj or .vbproj file (depending on the language). For instance console project, web api project etc.

Solution:

A Solution is a container for organizing one or more related Projects. It provides a higher-level view of the application or system being developed. Defined by a .sln file and contains reference to multiple projects.

A Simple representation of Solution and Project Hierarchy

MySolution.sln
β”‚
β”œβ”€β”€ WebApp.csproj
β”‚   β”œβ”€β”€ Controllers
β”‚   β”œβ”€β”€ Views
β”‚   └── Models
β”‚
β”œβ”€β”€ DataAccess.csproj
β”‚   └── Repositories
β”‚
└── Tests.csproj
    └── UnitTests

Enter fullscreen mode Exit fullscreen mode

Managing Development with .NET CLI

Let's create an empty solution first so that we can add one or more projects later on. Create a folder and open the folder with VS Code. Inside the VS Code terminal run -

> dotnet new sln -n VsCodePlay

I have named the solution VsCodePlay, and an empty solution has been created named "VsCodePlay.sln".

Let's create a webapi project inside this solution with this command -

> dotnet new webapi -n Todo.API

A webapi project with all the weatherforecast boilerplate has been created but it's still not part of VsCodePlay.sln, We can inspect that in Solution Explorer of VS Code.

State of the project

So run this command to add a project into a solution, The command should be run inside the root folder of the solution. In out case VsCodePlay folder -

> dotnet sln VsCodePlay.sln add Todo.API/Todo.API.csproj

I've included a second console application in the solution. The Solution Explorer now reflects this addition, as shown below. You can manage the application from the Solution Explorer alike Visual Studio.

Solution Explorer

You've already noticed that dotnet new command can create the boilerplate for you with just a single command. For inspecting the available project types in .NET you can run -

> dotnet new list

Available Projects

Using the .NET CLI, you can quickly generate a fully functional, basic project structure (boilerplate) for various project types, simply by using their short names.

We are now well-prepared to organize our project using the .NET CLI. Let’s explore some essential commands that will help streamline and manage our development process effectively.

Run the project in development mode

> dotnet run

If you don't want to restart the server manually for reflecting file changes then run the project in watch mode, It will continuously watch the file changes and automatically restart the server.

> dotnet watch run

Install a Nuget Package

> dotnet add package Newtonsoft.Json

Remove a Nuget Package

> dotnet remove package Newtonsoft.Json

Building a project for debugging

> dotnet build

Cleaning an existing build

> dotnet clean

Publishing a project as DLL in production

> dotnet publish "./Todo.API.csproj" -c Release -o ./publish

Publishing an entire solution

> dotnet publish -c Release

This command needs to be executed at the solution level.

Run the project in production mode

> dotnet ./publish/Todo.API.dll

Conclusion

VS Code, complemented by essential extensions and the .NET CLI, is a powerful tool for cross-platform C# application development. The insights shared in this post can help developers embrace .NET development on macOS, unlocking opportunities for innovation and project success.

cli Article's
30 articles in total
Favicon
RAG - Creating the SQLite database and config file
Favicon
Simplifying API Routes in Next.js with next-api-gen
Favicon
Modernizing HyperGraph's CLI: A Journey Towards Better Architecture
Favicon
Making Python CLIs More Maintainable: A Journey with Dynamic Command Loading
Favicon
Making Your CLI Applications Pop with Styled Outputs
Favicon
Makefile
Favicon
Can I start and stop Docker Desktop using CLI?
Favicon
How to Install and Run Redis Directly on macOS (Without Homebrew)
Favicon
From iTerm To WezTerm
Favicon
RAG - Designing the CLI interface
Favicon
Configuring Cisco firewall in Linux machine with Minicom
Favicon
KillPy: The Tool to Clean Up Your Python Virtual Environments 🧹🐍
Favicon
Ubuntu Linux Commands Categorized
Favicon
Rust-Powered Password Decrypter: Find the String Behind the Hash! πŸ¦€πŸ”’
Favicon
Mastering Vim and NvChad for Coding and Development: A Comprehensive Guide
Favicon
The Ultimate Cheat Sheet: CLI Man Pages, tldr, and cheat.sh
Favicon
Git Command Line Mastery: 10 Essential Commands for Version Control Using Git
Favicon
Building My First NPM Package: A CLI for Scaffolding Express Servers
Favicon
.NET Development Essentials on macOS with VS Code
Favicon
How to Configure AWS CLI on Linux
Favicon
Building a GitHub Activity CLI - A Ruby Journey
Favicon
Enhanced CIDR Block Calculator with Expanded Input Formats in Go
Favicon
using cat printer on linux
Favicon
Task Tracker CLI
Favicon
Context Dump: Simplifying AI File Preparation
Favicon
MyTask ToDo CLI Tool...
Favicon
I made wut – a CLI that explains your last command with an LLM
Favicon
Magento 2 commands for maintenance and deployment
Favicon
Rusty Journal: A Minimal and Efficient CLI Journal & ToDo App
Favicon
[Boost]

Featured ones: