General Add selection to next Find match ⇧⌘P, F1 Show Command Palette ⌘P Quick Open, Go to File ⇧⌘N New window/instance ⌘W ⌘Close window/instance. Uninstall Visual Studio 2019 for Mac Preview. Visual Studio 2019 for Mac Preview was launched as a separate preview, allowing you to continue to work with your Visual Studio 2017 for Mac install side-by-side. Now that Visual Studio 2019 for Mac has been released, you can now safely remove the Visual Studio 2019 for Mac Preview application.
-->You can use this guide to uninstall each component in Visual Studio for Mac individually by navigating to the relevant section, or you can use the scripts provided in the Uninstall Script section to uninstall everything.
Note
This information will only remove Visual Studio 2019 or 2017 for Mac from your machine. to uninstall Visual Studio Code, see this issue for details.
Uninstall Script
There are two scripts that can be used to uninstall Visual Studio for Mac and all components for your machine:
The following sections provide information on downloading and using the scripts.
Visual Studio for Mac and Xamarin script
You can uninstall Visual Studio and Xamarin components in one go by using the uninstall script.
This uninstall script contains most of the commands that you will find in the article. There are three main omissions from the script and are not included due to possible external dependencies. To remove this, jump to the relevant section below and remove them manually:
To run the script, do the following steps:
How To Update Include Path In Vs Code Mac
Right-click on the script and select Save As to save the file on your Mac.
Open Terminal and change the working directory to where the script was downloaded:
Make the script executable and the run it with sudo:
Finally, delete the uninstall script and remove Visual Studio for Mac from the dock (if it's there).
.NET Core script
The uninstall script for .NET Core is located in the dotnet cli repo
To run the script, do the following steps:
Right-click on the script and select Save As to save the file on your Mac.
Open Terminal and change the working directory to where the script was downloaded:
Make the script executable and the run it with sudo:
Finally, delete the .NET Core uninstall script.
Uninstall Visual Studio for Mac
The first step in uninstalling Visual Studio from a Mac is to locate Visual Studio.app in the /Applications directory and drag it to the Trash Can. Alternatively, right-click and select Move to Trash as illustrated in the following image:
Deleting this app bundle removes Visual Studio for Mac, even though there may be other files related to Xamarin still on the file system.
To remove all traces of Visual Studio for Mac, run the following commands in Terminal:
You may also want to remove the following directory containing various Xamarin files and folders. However, before you do you should be aware that this directory contains the Android signing keys. For more information refer to the section Uninstalling Android SDK and Java SDK:
Uninstall Mono SDK (MDK)
Mono is an open-source implementation of Microsoft's .NET Framework and is used by all Xamarin Products—Xamarin.iOS, Xamarin.Android, and Xamarin.Mac to allow development of these platforms in C#.
Warning
There are other applications outside of Visual Studio for Mac that also use Mono, such as Unity.Be sure that there are no other dependencies on Mono before uninstalling it.
To remove the Mono Framework from a machine, run the following commands in Terminal:
Uninstall Xamarin.Android
There are a number of items required for the installation and use of Xamarin.Android, such as the Android SDK and Java SDK.
Use the following commands to remove Xamarin.Android:
Uninstall Android SDK and Java SDK
The Android SDK is required for development of Android applications. To completely remove all parts of the Android SDK, locate the file at ~/Library/Developer/Xamarin/ and move it to Trash.
Warning
You should be aware that Android signing keys that are generated by Visual Studio for Mac are located in ~/Library/Developer/Xamarin/Keystore
. Make sure to back these up appropriately, or avoid removing this directory if you wish to keep your keystore.
The Java SDK (JDK) does not need to be uninstalled, as it is already pre-packaged as part of Mac OS X / macOS.
Uninstall Android AVD
Warning
There are other applications outside of Visual Studio for Mac that also use Android AVD and these additional android components, such as Android Studio.Removing this directory may cause projects to break in Android Studio.
To remove any Android AVDs and additional Android components use the following command:
To remove only the Android AVDs use the following command:
Uninstall Xamarin.iOS
Xamarin.iOS allows iOS application development using C# or F# with Visual Studio for Mac.
Use the following commands in Terminal to remove all Xamarin.iOS files from a file system:
Uninstall Xamarin.Mac
Xamarin.Mac can be removed from your machine using the following two commands to eradicate the product and license from your Mac respectively:
Uninstall Workbooks and Inspector
Starting with 1.2.2, Xamarin Workbooks & Inspector can be uninstalled from a terminal by running:
For older versions, you need to manually remove the following artifacts:
- Delete the Workbooks app at
'/Applications/Xamarin Workbooks.app'
- Delete the Inspector app at
'Applications/Xamarin Inspector.app'
- Delete the add-ins:
'~/Library/Application Support/XamarinStudio-6.0/LocalInstall/Addins/Xamarin.Interactive'
and'~/Library/Application Support/XamarinStudio-6.0/LocalInstall/Addins/Xamarin.Inspector'
- Delete Inspector and supporting files here:
/Library/Frameworks/Xamarin.Interactive.framework
and/Library/Frameworks/Xamarin.Inspector.framework
Uninstall the Xamarin Profiler
Uninstall the Visual Studio Installer
Use the following commands to remove all traces of the Xamarin Universal Installer:
Uninstall Visual Studio 2019 for Mac Preview
Visual Studio 2019 for Mac Preview was launched as a separate preview, allowing you to continue to work with your Visual Studio 2017 for Mac install side-by-side.
Now that Visual Studio 2019 for Mac has been released, you can now safely remove the Visual Studio 2019 for Mac Preview application.
To uninstall the preview application bundle, select Visual Studio (Preview) from your Applications folder and click Move to Trash, as depicted in the following image:
You can also remove the Preview plist file with the following command:
See also
-->Visual Studio for Mac makes it easy to develop your app's service with its support for the latest ASP.NET Core Web development platform. ASP.NET Core runs on .NET Core, the latest evolution of the .NET Framework and runtime. It's been tuned for fast performance, factored for small install sizes, and reimagined to run on Linux and macOS, as well as Windows.
Installing .NET Core
.NET Core 3.1 is automatically installed when you install Visual Studio for Mac. For more information about versions of .NET Core supported in Visual Studio for Mac, see .NET Core Support.
Creating an ASP.NET Core app in Visual Studio for Mac
Open Visual Studio for Mac. On the Start Screen, select New Project...
This will display the New Project dialog, allowing you to select a template to create your application.
There are a number of projects that will provide you with a pre-built template to start building your ASP.NET Core Application. These are:
- .NET Core > Empty
- .NET Core > API
- .NET Core > Web Application
- .NET Core > Web Application (Model-View-Controller)
- .NET Core > Blazor Server App
- .NET Core > Blazor WebAssembly App
Select the ASP.NET Core Empty Web Application and press Next. Give the Project a Name and press Create. This creates a new ASP.NET Core app. In the solution window's left pane, expand the second arrow and then select Startup.cs. It should look similar to the image below:
The ASP.NET Core Empty template creates a web application with two default files: Program.cs and Startup.cs, which are explained below. It also creates a Dependencies folder, which contains your project's NuGet package dependencies such as ASP.NET Core, the .NET Core framework, and the MSBuild targets that build the project:
Program.cs
Open and inspect the Program.cs file in your project. Notice that several things are happening in the Main
method – the entry into your app:
An ASP.NET Core app creates a web server in its main method by configuring and launching a host via an instance of WebHostBuilder
. This builder provides methods to allow the host to be configured. In the template app, the following configurations are used:
.UseStartup<Startup>()
: Specifies the Startup class.
However, you can also add additional configurations, such as:
UseKestrel
: Specifies the Kestrel server will be used by the appUseContentRoot(Directory.GetCurrentDirectory())
: Uses the web project's root folder as the app's content root when the app is started from this folder.UseIISIntegration()
: Specifies that the app should work with IIS. To use IIS with ASP.NET Core bothUseKestrel
andUseIISIntegration
need to be specified.
Startup.cs
The Startup class for your app is specified in the UseStartup()
method on the CreateWebHostBuilder
. It is in this class that you will specify the request handling pipeline, and where you configure any services.
Open and inspect the Startup.cs file in your project:
This Startup class must always adhere to the following rules:
- It must always be public
- It must contain the two public methods:
ConfigureServices
andConfigure
The ConfigureServices
method defines the services that will be used by your app.
The Configure
allows you to compose your request pipeline using Middleware. These are components used within an ASP.NET application pipeline to handle requests and responses. The HTTP pipeline consists of a number of request delegates, called in sequence. Each delegate can choose to either handle the request itself, or pass it to the next delegate.
Vs Code Mac M1
You can configure delegates by using the Run
,Map
, and Use
methods on IApplicationBuilder
, but the Run
method will never call a next delegate and should always be used at the end of your pipeline.
The Configure
method of the pre-built template is built to do a few things. First, it configures an exception handling page for use during development. Then, it sends a response to the requesting web page with a simple 'Hello World'.
This simple Hello, World project can run now without any additional code being added. To run the app, you can either select which browser you want to run app the app in using the dropdown right of the Play button, or simply hit the Play (triangular) button to use your default browser:
Visual Studio for Mac uses a random port to launch your web project. To find out what port this is, open the Application Output, which is listed under the View > Other Windows menu. You should find output similar to that shown below:
Once the project is running, your default web browser should launch and connect to the URL listed in the Application Output. Alternatively, you can open any browser of your choice, and enter http://localhost:5000/
, replacing the 5000
with the port that Visual Studio output in the Application Output. You should see the text Hello World!
:
Adding a Controller
ASP.NET Core Apps use the Model-View-Controller (MVC) design pattern to provide a logical separation of responsibilities for each part of the app. The MVC design pattern consists of the following concepts:
- Model: A class that represents the data of the app.
- View: Displays the app's user interface (which is often the model data).
- Controller: A class which handles browser requests, responds to user input and interaction.
For more information on using MVC, see the Overview of ASP.NET Core MVC guide.
To add a controller, do the following:
Right-click on the Project name and select Add > New Files. Select General > Empty Class, and enter a controller name:
Add the following code to the new controller:
Add the
Microsoft.AspNetCore.Mvc
dependency to the project by right-clicking the Dependency folder, and selecting Add Package....Use the Search box to browse the NuGet library for
Microsoft.AspNetCore.Mvc
, and select Add Package. This may take a few minutes to install and you may be prompted to accept various licenses for the required dependencies:In the Startup class, remove the
app.Run
lambda and set the URL routing logic used by MVC to determine which code it should invoke to the following:Make sure to remove the
app.Run
lambda, as this will override the routing logic.MVC uses the following format, to determine which code to run:
/[Controller]/[ActionName]/[Parameters]
When you add the code snippet above, you are telling the app to default to the
HelloWorld
Controller, and theIndex
action method.Add the
services.AddMvc();
call to theConfigureServices
method, as illustrated below:You can also pass parameter information from the URL to the controller.
Add another method to your HelloWorldController, as illustrated below:
If you run the app now, it should automatically open your browser:
Try to browse to
http://localhost:xxxx/HelloWorld/Xamarin?name=Amy
(replacingxxxx
with the correct port), you should see the following:
Troubleshooting
If you need to install .NET Core manually on macOS 10.12 (Sierra) and higher, do the following:
Before you start installing .NET Core, ensure that you have updated all OS updates to the latest stable version. You can check this by going to the App Store application, and selecting the Updates tab.
Follow the steps listed on the .NET Core site.
Make sure to complete all steps successfully to ensure that .NET Core is installed successfully.
Summary
This guide gave an introduction to ASP.NET Core. It describes what it is, when to use it, and provided information on using it in Visual Studio for Mac.For more information on the next steps from here, see the following guides:
- ASP.NET Core docs.
- Creating Backend Services for Native Mobile Applications, which shows how to build a REST service using ASP.NET Core for a Xamarin.Forms app.
- ASP.NET Core hands-on lab.