-->
In this tutorial, you create a class library that contains a single string-handling method.
Perhaps that's for the developers to implement with their programs, I don't know if there is a Mac client so you can access.Net. Ask the website your visiting to do something so your Mac can also visit and use the site.
A class library defines types and methods that are called by an application. If the library targets .NET Standard 2.0, it can be called by any .NET implementation (including .NET Framework) that supports .NET Standard 2.0. If the library targets .NET 5, it can be called by any application that targets .NET 5. This tutorial shows how to target .NET 5.
Perhaps that's for the developers to implement with their programs, I don't know if there is a Mac client so you can access.Net. Ask the website your visiting to do something so your Mac can also visit and use the site. Xamarin.Mac enables.NET developers to develop full native Mac applications with C#. Under the hood, accessing native macOS APIs is the same as with Objective-C or Swift development. I will start with empty macOS Cocoa/C# application. Then I will put some GUI elements and wire-up control properties and events with a C# logic. But I don't want to shut out users on the Mac or on Linux. OK, they can run Web applications, or use.Net Web Services, but that's not enough. I want to deliver those users my.Net executable and have them be able to run it. It runs:.Net on the Mac. Well, there's Mono. It looks good and I hope it succeeds.
Note
Your feedback is highly valued. There are two ways you can provide feedback to the development team on Visual Studio for Mac:
- In Visual Studio for Mac, select Help > Report a Problem from the menu or Report a Problem from the Welcome screen, which opens a window for filing a bug report. You can track your feedback in the Developer Community portal.
- To make a suggestion, select Help > Provide a Suggestion from the menu or Provide a Suggestion from the Welcome screen, which takes you to the Visual Studio for Mac Developer Community webpage.
Prerequisites
Install Visual Studio for Mac version 8.8 or later. Select the option to install .NET Core. Installing Xamarin is optional for .NET development. For more information, see the following resources:
- Tutorial: Install Visual Studio for Mac.
- Supported macOS versions.
- .NET versions supported by Visual Studio for Mac.
Create a solution with a class library project
.net For Mac Os
A Visual Studio solution serves as a container for one or more projects. Create a solution and a class library project in the solution. You'll add additional, related projects to the same solution later.
Start Visual Studio for Mac.
In the start window, select New Project.
In the Choose a template for your new project dialog select Web and Console > Library > Class Library, and then select Next.
In the Configure your new Class Library dialog, choose .NET 5.0, and select Next.
Name the project 'StringLibrary' and the solution 'ClassLibraryProjects'. Leave Create a project directory within the solution directory selected. Select Create.
From the main menu, select View > Solution, and select the dock icon to keep the pad open.
In the Solution pad, expand the
StringLibrary
node to reveal the class file provided by the template, Class1.cs. ctrl-click the file, select Rename from the context menu, and rename the file to StringLibrary.cs. Open the file and replace the contents with the following code:Press ⌘S (command+S) to save the file.
Select Errors in the margin at the bottom of the IDE window to open the Errors panel. Select the Build Output button.
Select Build > Build All from the menu.
The solution builds. The build output panel shows that the build is successful.
Add a console app to the solution
Add a console application that uses the class library. The app will prompt the user to enter a string and report whether the string begins with an uppercase character.
In the Solution pad, ctrl-click the
ClassLibraryProjects
solution. Add a new Console Application project by selecting the template from the Web and Console > App templates, and select Next.Select .NET 5.0 as the Target Framework and select Next.
Name the project ShowCase. Select Create to create the project in the solution.
Open the Program.cs file. Replace the code with the following code:
The program prompts the user to enter a string. It indicates whether the string starts with an uppercase character. If the user presses the enter key without entering a string, the application ends, and the console window closes.
The code uses the
row
variable to maintain a count of the number of rows of data written to the console window. Whenever it's greater than or equal to 25, the code clears the console window and displays a message to the user.
.net For Macbook
Add a project reference
Initially, the new console app project doesn't have access to the class library. To allow it to call methods in the class library, create a project reference to the class library project.
In the Solutions pad, ctrl-click the Dependencies node of the new ShowCase project. In the context menu, select Add Reference.
In the References dialog, select StringLibrary and select OK.
.net For Mac M1
Prerequisites
Install Visual Studio for Mac version 8.8 or later. Select the option to install .NET Core. Installing Xamarin is optional for .NET development. For more information, see the following resources:
- Tutorial: Install Visual Studio for Mac.
- Supported macOS versions.
- .NET versions supported by Visual Studio for Mac.
Create a solution with a class library project
.net For Mac Os
A Visual Studio solution serves as a container for one or more projects. Create a solution and a class library project in the solution. You'll add additional, related projects to the same solution later.
Start Visual Studio for Mac.
In the start window, select New Project.
In the Choose a template for your new project dialog select Web and Console > Library > Class Library, and then select Next.
In the Configure your new Class Library dialog, choose .NET 5.0, and select Next.
Name the project 'StringLibrary' and the solution 'ClassLibraryProjects'. Leave Create a project directory within the solution directory selected. Select Create.
From the main menu, select View > Solution, and select the dock icon to keep the pad open.
In the Solution pad, expand the
StringLibrary
node to reveal the class file provided by the template, Class1.cs. ctrl-click the file, select Rename from the context menu, and rename the file to StringLibrary.cs. Open the file and replace the contents with the following code:Press ⌘S (command+S) to save the file.
Select Errors in the margin at the bottom of the IDE window to open the Errors panel. Select the Build Output button.
Select Build > Build All from the menu.
The solution builds. The build output panel shows that the build is successful.
Add a console app to the solution
Add a console application that uses the class library. The app will prompt the user to enter a string and report whether the string begins with an uppercase character.
In the Solution pad, ctrl-click the
ClassLibraryProjects
solution. Add a new Console Application project by selecting the template from the Web and Console > App templates, and select Next.Select .NET 5.0 as the Target Framework and select Next.
Name the project ShowCase. Select Create to create the project in the solution.
Open the Program.cs file. Replace the code with the following code:
The program prompts the user to enter a string. It indicates whether the string starts with an uppercase character. If the user presses the enter key without entering a string, the application ends, and the console window closes.
The code uses the
row
variable to maintain a count of the number of rows of data written to the console window. Whenever it's greater than or equal to 25, the code clears the console window and displays a message to the user.
.net For Macbook
Add a project reference
Initially, the new console app project doesn't have access to the class library. To allow it to call methods in the class library, create a project reference to the class library project.
In the Solutions pad, ctrl-click the Dependencies node of the new ShowCase project. In the context menu, select Add Reference.
In the References dialog, select StringLibrary and select OK.
.net For Mac M1
.net For Mac Download
Run the app
ctrl-click the ShowCase project and select Run project from the context menu.
Try out the program by entering strings and pressing enter, then press enter to exit.
Additional resources
- .NET Standard versions and the platforms they support.
Next steps
Paint.net For Mac
In this tutorial, you created a solution and a library project, and added a console app project that uses the library. In the next tutorial, you add a unit test project to the solution.