Using Visual Studio For Mac Asp.net Core Mvc

Add a controller to an ASP.NET Core MVC app with Visual Studio for Mac.; 5 minutes to read Contributors. In this article. By Rick Anderson. The Model-View-Controller (MVC) architectural pattern separates an app into three main components: Model, View, and Controller.The MVC pattern helps you create apps that are more testable and easier to update than traditional monolithic apps. I used the prebuilt Azure VM for VS 15.8 Preview, installed ASP.NET Core 2.1 RC1 and created a new web project using the ASP.NET Core MVC template. The example project created lacks the bundleconfig.json and any example of client-side library package management. ASP.NET Core MVC - Excel Reporting using Visual Studio Code for Mac / Linux / Windows Follow these steps to create a simple ASP.NET MVC Core Web App with Visual Studio Code for Mac / Linux / Windows that utilizes SpreadsheetGear for.NET Standard to generate and stream a Microsoft Excel workbook to the browser. I own a Mac and it is really great to use Visual Studio to create ASP.net core applications, but my partners have Windows machines. The thing is, if I create a repository and push my MVC project to GitHub, my partners can't open the solution from the repo, neither by cloning the project nor downloading the zip.

Active1 year, 11 months ago
  1. Introduction to ASP.NET Core MVC on macOS, Linux, or Windows.; 2 minutes to read Contributors. In this article. By Rick Anderson. This tutorial will teach you the basics of building an ASP.NET Core MVC web app using Visual Studio Code.
  2. We're going to be building this app with ASP.NET MVC Core 1.1. In the classroom, we'll use Visual Studio on Mac. While instructions in this lesson are specific for the Mac version of Visual Studio, the same project with the same file structure and code can be built with Visual Studio on Windows.

I realize this is a bit insane, C# being a Windows language and all, but I want to start learning C# mostly because I'm interested in ASP.NET MVC. I work as a web developer by day and my office is completely run on *nix machines. The developers and all other staff use Mac OS X and our servers are all some variation of Linux.

To be honest I just want to try something different than PHP, Python, or Ruby. The catch is that I don't want to give up my beloved Mac OS X. I've looked at Mono a bit and it seems like exactly what I am looking for. Unfortunately MonoDevelop is very slow to the point of uselessness on Mac OS X. (Unless I'm doing something wrong which is entirely plausible).

So my question boils down to this: What is the best way to code and compile C# apps on Mac OS X. (Running the code is not that big of issue, I'll probably just get some cheap server space to run my ASP.NET MVC apps on. I'm not really looking to run any apps on Mac OS X.)

macinjoshmacinjosh
3,6668 gold badges41 silver badges66 bronze badges
Studio

8 Answers

In my own experience as a C#/Windows/ASP.Net developer the greatest strength of the platform is the integration with the tools. That said it is difficult to get it all running on mono. Mono would be an excellent deployment platform. But if you want to learn asp.net MVC your best bet is to set up a virtual Windows environment and get the free visual web developer visual studio: http://www.microsoft.com/express/vwd/ .

The other reason is that if you're trying to learn the platform, most resources will use some variant of Visual Studio. I find it rather difficult to try and learn a framework and have to struggle with platform differences at the same time.

I say this as an avid OS X user that has done C# development for several years and has done several small projects in asp.net mvc.

MinMin
2,8701 gold badge15 silver badges23 bronze badges

what about running a virtual Windows machine on your Mac?

see http://www.parallels.com/eu/products/desktop/

jaojao
13.4k13 gold badges50 silver badges91 bronze badges

+1 to Min's answer.

The tools Microsoft provides (free and purchased) are amazing and integrate very well. The more I use Visual Studio, the more I love it.

I highly suggest doing your dev for ASP.NET/C# on Windows (bootcamp or vmware or w/e).

Having to switch between OSes when you want to code is a small price to pay compared to the potential compatibility headaches you might face in the future.

Community
OmarOmar
27.1k39 gold badges124 silver badges198 bronze badges

I'd add to the virtualisation argument. If you were to go for a Windows installation in VMWare Fusion, for example, you can run it in coherence mode. In this mode, you still get all the apps and system you know and love in OS X, and make Visual Studio appear as if tit were a native OS X app. VS, though, 'sees' the Windows environment, so you get the benfits of developing on Windows.

Of course, you have the overhead of having two OSs competing for resources, but most of the time this is not an issue (It isn't to me, anyway, and I run my own projects at home this way on a humble MacBook)

ZombieSheepZombieSheep
26.7k10 gold badges60 silver badges107 bronze badges

In case anyone ends up on this question, ASP.NET Core is now out and runs on the Mac. MS has a walkthru detailing creating a Web API with ASP.NET Core: https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-vsc

user783836user783836
1,2201 gold badge14 silver badges24 bronze badges

I concur with a virtual windows machine and VS Express, but Mono Develop is not that bad when especially targeting ASP.NET MVC.

kennykenny
15.2k6 gold badges44 silver badges80 bronze badges

Developing in .net is quite highly IDE-oriented. Of course you can do it all in a plain old text editor but it gets harder and harder unless you're writing back-end server code only. Maybe there are great mono-based IDEs but I can't see why you'd prefer to use MacOS when all the time will be spent using the IDE anyway.

Definitely vote for virtualized Windows or using BootCamp.

Mr. BoyMr. Boy
23.3k74 gold badges253 silver badges477 bronze badges

You could install a linux desktop on your mac (KDE) and use wine(a linux windows emulator app) to install Visual studio express. The KDE desktop runs on a mac. Now you do not have to install a complete windows os on your machine.

Andy
6,7713 gold badges28 silver badges66 bronze badges
Peter-TIPeter-TI

Not the answer you're looking for? Browse other questions tagged c#asp.net-mvcmonomacosmonodevelop or ask your own question.

By Daniel Roth, Steve Smith and Rick Anderson

This article will show you how to write your first ASP.NET Core application on a Mac.

Sections:

To setup your development machine download and install .NET Core and Visual Studio Code with the C# extension.

Follow the instruction in Building Projects with Yeoman to create an ASP.NET Core project.

  • Start Visual Studio Code
  • Tap File > Open and navigate to your Empty ASP.NET Core app

From a Terminal / bash prompt, run dotnetrestore to restore the project’s dependencies. Alternately, you can enter commandshiftp in Visual Studio Code and then type dot as shown:

You can run commands directly from within Visual Studio Code, including dotnetrestore and any tools referenced in the project.json file, as well as custom tasks defined in .vscode/tasks.json.

This empty project template simply displays “Hello World!”. Open Startup.cs in Visual Studio Code to see how this is configured:

Using Visual Studio For Mac Asp.net Core Mvc

If this is your first time using Visual Studio Code (or just Code for short), note that it provides a very streamlined, fast, clean interface for quickly working with files, while still providing tooling to make writing code extremely productive.

In the left navigation bar, there are four icons, representing four viewlets:

  • Explore
  • Search
  • Git
  • Debug

The Explore viewlet allows you to quickly navigate within the folder system, as well as easily see the files you are currently working with. It displays a badge to indicate whether any files have unsaved changes, and new folders and files can easily be created (without having to open a separate dialog window). You can easily Save All from a menu option that appears on mouse over, as well.

The Search viewlet allows you to quickly search within the folder structure, searching filenames as well as contents.

Code will integrate with Git if it is installed on your system. You can easily initialize a new repository, make commits, and push changes from the Git viewlet.

The Debug viewlet supports interactive debugging of applications.

Finally, Code’s editor has a ton of great features. You’ll notice unused using statements are underlined and can be removed automatically by using command. when the lightbulb icon appears. Classes and methods also display how many references there are in the project to them. If you’re coming from Visual Studio, Code includes many of the same keyboard shortcuts, such as commandkc to comment a block of code, and commandku to uncomment.

The sample is configured to use Kestrel for the web server. You can see it configured in the project.json file, where it is specified as a dependency.

  • Run dotnetrun command to launch the app
  • Navigate to localhost:5000:
  • To stop the web server enter Ctrl+C.
Mac

Once you’ve developed your application, you can easily use the Git integration built into Visual Studio Code to push updates to production, hosted on Microsoft Azure.

Using Visual Studio For Mac Asp Net Core Mvc

Initialize Git¶

Initialize Git in the folder you’re working in. Tap on the Git viewlet and click the InitializeGitrepository button.

Add a commit message and tap enter or tap the checkmark icon to commit the staged files.

Git is tracking changes, so if you make an update to a file, the Git viewlet will display the files that have changed since your last commit.

Initialize Azure Website¶

You can deploy to Azure Web Apps directly using Git.

Using Visual Studio For Mac Asp.net Core Mvc Conference

  • Create a new Web App in Azure. If you don’t have an Azure account, you can create a free trial.
  • Configure the Web App in Azure to support continuous deployment using Git.

Using Visual Studio For Mac Asp Net Core Mvc Using

Record the Git URL for the Web App from the Azure portal:

Microsoft Visual Studio For Mac

  • In a Terminal window, add a remote named azure with the Git URL you noted previously.

    • gitremoteaddazurehttps://ardalis-git@firstaspnetcoremac.scm.azurewebsites.net:443/firstaspnetcoremac.git
  • Push to master.

    • gitpushazuremaster to deploy.
  • Browse to the newly deployed web app. You should see Helloworld!