Using .NET
ServBay provides a convenient and efficient development environment for .NET developers on macOS. With ServBay's package management system, you can easily install, manage, and run multiple versions of the .NET SDK, including both modern .NET (i.e. .NET Core and later) and the classic Mono framework, to meet the requirements of different projects.
Overview
.NET Platform History and macOS Support
.NET is a versatile development platform developed by Microsoft. Understanding its history and evolution is essential for knowing its support on macOS:
.NET Framework (Original Version): First released in 2002, the .NET Framework was Microsoft's flagship development platform, but it was primarily designed for Windows systems. It contains the Common Language Runtime (CLR) and a vast Framework Class Library (FCL). Running .NET Framework applications directly on macOS is usually not possible.
Mono (The Cross-Platform Pioneer): To bring .NET applications to non-Windows platforms such as Linux and macOS, the community (initiated by Ximian, later backed by Novell and Xamarin/Microsoft) developed Mono. Mono is an open-source, cross-platform implementation of the .NET Framework. It allows developers to run and build applications originally written for .NET Framework (especially C# apps) on macOS and Linux. Mono still holds value today for scenarios where you need to run older .NET Framework apps or libraries on macOS.
.NET Core / .NET 5+ (Modern Cross-Platform Standard): Recognizing the importance of cross-platform development, Microsoft created .NET Core from the ground up. This is a modern, high-performance, open-source, fully cross-platform implementation of .NET, supporting Windows, macOS, and Linux. After .NET Core 3.1, the platform was rebranded as .NET (starting with version 5, skipping 4 to avoid confusion with .NET Framework 4.x). Today, when we refer to the .NET SDK, we are usually talking about this modern, cross-platform version (.NET 5, 6, 7, 8, 9, 10, etc.). This is the platform Microsoft recommends for all new application development, including on macOS.
ServBay's Support for .NET
ServBay recognizes both the historical development of .NET and the diverse needs of developers, and thus offers:
- Modern .NET SDK Packages: Bundles of various .NET (Core) versions (e.g., .NET SDK 2.0 to 10.0), so you can use the latest C#, F#, and ASP.NET Core for cross-platform development.
- Mono Packages: Provides the Mono runtime (e.g., Mono 6) to support legacy .NET Framework-based projects or specific libraries on macOS, including limited support for legacy ASP.NET (Web Forms, System.Web MVC).
- Parallel Installation: Install multiple .NET SDK and Mono versions simultaneously.
- Per-Project Version Control: Specify the required modern .NET SDK version for each project using a
.servbay.config
file. - Simplified Management: Intuitively view, install, and uninstall various SDKs and Mono versions via ServBay's graphical interface.
Accessing .NET Packages
- Open the ServBay application.
- In the left navigation bar, click on
Packages
. - On the
Packages
page, scroll down or selectLanguages
->.NET
in the sidebar. - The right panel will display a list of all available .NET SDK and Mono packages.
Installing a .NET SDK
The package list clearly shows the status of each .NET SDK version:
- Package Name: The name of the package, such as
.NET SDK 8.0
orMono 6
. - Version: The specific version number of the package.
- Status: Indicates
Installed
orNot Installed
. - Control: Actions you can take.
To install a .NET SDK version that isn't yet installed (for example, .NET SDK 10.0
):
- Find your desired version in the list.
- Make sure its status is
Not Installed
. - Click the Download/Install icon (usually a downward arrow) at the far right of its row.
- ServBay will start downloading and installing the selected SDK version. This may take a while, depending on your network speed and the size of the SDK.
- Once installed, the status will change to
Installed
, and the control icon will switch to the Uninstall icon (trash can).
Managing Installed SDKs
- View Installed Versions: SDKs and Mono versions marked as
Installed
are the ones currently available in your environment. - Uninstall SDKs: If you no longer need an SDK version, simply click its Uninstall icon (trash can) and confirm to remove it from your system.
Using Installed .NET SDKs
When you install a .NET SDK via ServBay, the related dotnet
command-line tools are typically added to your PATH environment variable (when the ServBay environment is active). This means you can use the dotnet
command directly in your macOS Terminal.
Common Command Examples:
Check Available SDKs: Open Terminal and run:
bashdotnet --list-sdks
1This will display all .NET SDK versions managed by ServBay and their install paths.
Check the Current Active SDK Version (usually the most recently installed or globally configured one):
bashdotnet --version
1Create a New Console Application (using the default SDK):
bash# Create a project folder named MyConsoleApp mkdir MyConsoleApp cd MyConsoleApp # Create a new console project using the default SDK dotnet new console
1
2
3
4
5
6Run the Application:
bashdotnet run
1Use a Specific SDK Version (if needed): If your project requires a specific SDK version, you can specify it via the
global.json
file. In your project root directory, create aglobal.json
file with contents like:json{ "sdk": { "version": "8.0.408" // Specify the SDK version you've installed and your project needs } }
1
2
3
4
5When you run the
dotnet
command in that project folder, it will prioritize the SDK version set in theglobal.json
file.
Mono Support
Besides the standard .NET SDK, ServBay also provides installation options for Mono. Mono is an open-source, cross-platform implementation of the .NET Framework. If you need to run or develop applications that depend on certain .NET Framework features, you can install and use Mono via ServBay. The installation and uninstallation process is identical to that of the .NET SDK.
Mono is mainly used to run programs compiled for the .NET Framework (.exe
files) or to use tools that require the Mono environment, including running legacy ASP.NET applications.
Check Mono Version:
bashmono --version
1Run a .NET Framework Executable: If you have an executable like
LegacyApp.exe
compiled for the .NET Framework:bashmono LegacyApp.exe
1Run Legacy ASP.NET Applications (Limited Support): Mono includes a lightweight web server named
xsp
, which can be used to run legacy ASP.NET Web Forms or System.Web MVC apps in a development environment. You can also integrate with Nginx + FastCGI or Apache + mod_mono.Important Notes:
- This approach offers limited compatibility with the ASP.NET Framework. Not all applications will run perfectly, especially those relying on Windows-specific features.
- Performance is typically inferior to running on Windows/IIS.
- Not recommended for new projects. Modern web development should use ASP.NET Core.
- ServBay provides a complete guide: How to Run ASP.NET Framework 4.x Websites on macOS.
If you do need to run such an app (for testing or maintenance, for example), you may use a command like the following (the exact command depends on your application and configuration):
bash# Example: Start the xsp server in a specific directory # cd /Applications/ServBay/www/your_legacy_aspnet_app # xsp4 --port 8080 # (xsp4 for .NET 4.x)
1
2
3
Integrated Web Server (ASP.NET Core)
With ServBay-installed .NET SDKs, you can develop ASP.NET Core web applications. When deploying these applications, you can leverage ServBay's built-in web servers (such as Nginx, Caddy, or Apache):
- Use the
dotnet publish
command to publish your ASP.NET Core app. - In ServBay, add a new Website.
- Configure the site as a reverse proxy to forward requests to the Kestrel server port your app is listening on (e.g.,
http://localhost:5000
). The specific reverse proxy setup depends on your choice of web server (Nginx, Caddy, or Apache).
For detailed steps, refer to the ServBay documentation on adding websites and configuring reverse proxies.
Summary
ServBay greatly streamlines the setup and management of .NET development environments on macOS. Thanks to its intuitive interface, developers can easily install, switch, and remove multiple .NET SDK versions and Mono, freeing you to focus on building and testing your C#, F#, and ASP.NET Core applications.