The Visual Studio for Mac editor supports powerful built-in refactoring options such as Extract Method and Rename, accessible via the Quick Actions menu. Integrated Source Control Manage your code in Git or SVN repos hosted by any provider, including GitHub and Azure DevOps. This tutorial takes you through installing a FREE copy of Visual Studio for Mac on your machine to create your first C# app, compile it, and debug it. Start downloading Visual Studio 2019 Community at. Visual Studio IDE Visual Studio for Mac Visual Studio Code To continue downloading, click here Visual Studio Community 2019 – Free IDE and Developer Tools 2020-05-04T13:32:31-07:00. Are there plans for a SSMS to run on Mac OSX, since there is a Visual Studio for Mac? Thursday, July 20, 2017 9:31 AM.
- Microsoft Visual Studio Download
- Microsoft Visual Studio C++ For Mac
- Visual Studio 2017 Mac Download
- Visual Studio For Macos
- Microsoft Visual Studio Format Code
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 pad'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
![Microsoft visual studio 2019 Microsoft visual studio 2019](https://tecnologia21.com/wp-content/uploads/2019/04/visual-studio-2019-mac.jpg)
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.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
Snapchat messenger for mac. 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 View > Pads. You should find output similar to that shown below:
Microsoft Visual Studio Download
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. MVC consists of the following:
- 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 refer to 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 theapp.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 theHelloWorld
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 Mac OS 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, refer to 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.
Related Video
Hands On Microsoft this week opened the gates on Visual Studio for Mac 2019 8.3, a flexible development environment for .NET, and The Reg can give you the lowdown on some of the new features.
But first, let's see how the Microsofties got here. Redmond has three coding tools under the Visual Studio brand, all of which have different ancestries.
Microsoft Visual Studio C++ For Mac
Visual Studio on Windows supports development not only in .NET languages but also C++, Python, JavaScript and Node.js, and cross-platform mobile development using Xamarin, Apache Cordova or C++. Depending on which edition you have, you also get SQL Server database tools, test and coverage frameworks, Microsoft Office and SharePoint development, R for data science work, built-in Docker tools and more.
Xamarin is a cross-platform .NET framework designed mainly for iOS and Android, but also with support for macOS applications. A confusing thing is that Xamarin does not use .NET Core, though it does support the .NET Standard 2.1 specification in its latest version. See here for guidance.
Xamarin evolved from the open-source Mono framework, an implementation of .NET for Windows and Linux. Mono had its own IDE, called MonoDevelop, which unlike Visual Studio was originally written entirely in C#. Xamarin adapted MonoDevelop to become Xamarin Studio. When Microsoft acquired Xamarin in 2016, Xamarin Studio became a Mac-only IDE and was renamed Visual Studio for Mac. You can still get MonoDevelop for Mac, Windows and Linux, though the Mac download is now Visual Studio for Mac, and on Windows you have to build it from source.
Visual Studio Code (VS Code) is a cross-platform editor built with the Electron framework, using Node.js and the Chromium browser engine Blink. VS Code was first previewed in 2015 and has been a remarkable success, now ranking as the top development environment on the popular coding Q&A site StackOverflow by a huge margin. Although lightweight in comparison to Visual Studio, VS Code straddles the boundary between an editor and an IDE, with debugging support and a rich range of extensions.
Following the acquisition, Microsoft has been working on sharing some of its Visual Studio for Windows technology with the Mac version. This goes alongside the development of the cross-platform .NET Core, which has allowed code sharing between Mono and .NET Core, though Mono has not been completely replaced. It is still the case that Visual Studio for the Mac is a very different thing from Visual Studio for Windows.
What can Visual Studio for Mac do?
VS Mac is primarily for Xamarin development. The majority of Xamarin developers code applications for iOS and Android, and there are two different approaches to this.
Xamarin.iOS and Xamarin.Android let you write non-visual code in C# while using native tools to build the UI, Xcode for iOS or a built-in Android designer for Android.
Xamarin Forms is a cross-platform GUI framework. You design the user interface with XAML and build for your chosen target platforms.
You can also go beyond iOS and Android. Xamarin.Mac is for Cocoa applications and uses a similar model to Xamarin.iOS. Xamarin Forms can also target Windows UWP (Universal Windows Platform) and, in preview, macOS.
There is also steadily improving support for games development with Unity.
A glance at the Xamarin forums gives a crude guide to usage. Xamarin Forms has more than double the activity of any other section (over 51,000 threads). Xamarin.Android 34,000, Xamarin.iOS 21,000, and relatively low activity elsewhere – 343 threads for Xamarin.Mac, for example.
Xamarin Forms Mac support seems to be moribund; it was announced in 2017 but the platform status here was last updated in May 2018 and remains incomplete.
Visual Studio for the Mac also supports ASP.NET Core development using Razor, Angular or React.js, and serverless with Azure Functions.
Under the Vulture's Claw
A cross-platform Xamarin Forms app running on iOS and Android
Visual Studio 2017 Mac Download
We installed VS Mac on a 2018 Mac Mini. The installer pulls down the Android SDK for you, but you have to install Xcode separately. All straightforward, but there is a puzzle about .NET Core. Version 3.0 is installed automatically, and you can create ASP.NET Core apps, but when you go to create a mobile app, the option to create an ASP.NET Core API back end is disabled because it 'requires an ASP.NET Core installation'.
The look and feel of the IDE is different from Visual Studio on Windows, as you would expect from the product history. It feels more basic and less refined, and has only a fraction of the features of its similarly named cousin.
Visual Studio For Macos
There is no visual designer for Xamarin Forms, but there is a visual preview. Unfortunately, this did not work for iOS on our very simple demo app, showing instead a MonoTouch exception message. But the app itself worked fine on both Android and iOS. The IDE did crash once or twice but with no loss of work.
Another experiment was to create a Xamarin.Mac application and edit the generated storyboard, which defines the user interface using Xcode. This worked perfectly.
What's new?
VS Mac 8.3 supports .NET Core 3 and C# 8.0, and Xamarin now supports Android 10, Xcode 11 and iOS 13.
One of the big new features, though in preview, is XAML hot reload in Xamarin Forms. This lets you amend the XAML file defining your UI, save it, and see the changes instantly in the app running on an emulator or device.
The Visual Studio Mac native editor shares code with Visual Studio on Windows
The C# editor in VS Mac was rewritten by the Visual Studio team after the Microsoft acquisition. It now has what Microsoft calls a 'fully native UI', raising the interesting question of how much of the old MonoDevelop code, which used cross-platform Gtk#, remains in VS Mac. The new native editor was fully released in July, but VS Mac 8.3 now supports web editing (JavaScript, TypeScript, HTML, CSS and more). This lets Microsoft share more features between Visual Studio on Windows and VS Mac, including improved IntelliSense. You also get proper bidirectional text support and a natty feature called multi-caret editing that lets you overtype multiple regions of selected text simultaneously.
There is a new dialog for the NuGet package manager, but care is needed because not all NuGet packages will work on the Mac.
These are highlights; the full list of what's new is here.
Observations
Microsoft has two successful Visual Studio development tools, and then there is VS Mac, which is important only for Mac-based Xamarin developers. Xamarin.Mac and Xamarin Forms targeting macOS are both interesting for .NET developers wondering how to get their Windows apps onto a Mac, but both are neglected relative to iOS and Android. If you want to develop for ASP.NET Core you would be better off with Visual Studio on Windows, and probably better off with VS Code with its much larger community and rich extension support. Strategically, it might make sense for Microsoft to invest in making VS Code more useful for Xamarin developers. All that said, VS Mac is substantially improved and the price is right: even the free Community edition is a capable tool. ®
Microsoft Visual Studio Format Code
Get ourTech Resources