In the recent times we have seen some steps taken by Microsoft which are really encouraging for the .Net community and Microsoft customers as a whole. They have taken some bold actions to change the restrictive image that we used to have for Microsoft, its platform and tools. Some of the brave actions which indicate that Microsoft is moving away from proprietary product based company to a service based organisationย are:
- They have open-sourced .Net Core, Asp.Net and MVC frameworks (including the compiler platform Roslyn).
- Azure platform now offers full support for open source tools like Hadoop (not to mention Linux distros which are also available).
Today I setup a full blown development environment for Asp.Net on Mac using tools which are free and open source. In this postย I will list downย the process of creating an Asp.Net website using yeoman and then running it using “dotnet” CLI on MacBook. Before I start I would like to say that they have managed to combine the process so seamlessly with a variety of tools that you get both the power that was generally associated with Unix based environments and the great scaffolding experience that was an MO for Microsoft development environment (Visual Studio). They have done a pretty good job of using the open source tools to provide the almost same experience (not exact because Visual Studio is a mature product and has been around since I was a kid). The code for Asp.Net website so created is platform independent and it can be hosted on any platform and in fact you can take this project as it isย and use it in Visual Studio 2015.
Step 1: Install .Net Core (detailed instructions areย here)
.Net Core is the runtime and framework package that is open source and runs on Windows, Mac and Linux (almost all – I have not verified it yet but there is a articleย describing the process of setting up and publishing applications to Linux). What does it mean, it means that now you can have Asp.Net applications running on any platform (including IoT devices like Raspberry pi, MinnowBoard etc.). I will write a separate postย about IoT development choices.
Step 2: Install Visual Studio Code (detailed instructions are here)
Visual studio code is a general purpose free code editor which can be extended with free community extensions and productivity tools. Its a general purpose code editor which means that you can do any kind of code editing and then have platform specific execution and debugging extensions plugged in. After installing Visual studio code you need to installย C# extensionย for Visual studio code. C# extension enables you to create/refactor/analyse and run andย debug C# code from Visual studio code. It providesย features like syntax highlighting, code completion and intellisense inside Visual studio code.
Step 3: Installย NodeJsย package with NPM.
NPM is a package manager which would come handy for installing packages and tools like yeoman, bower and gulp which will assist us in various stages of Asp.Net application development.
Step 4: Installย yeoman Asp.Net generator for scaffolding
Yeoman is a scaffolding/template tool that generates project and structures for given set of client tools. What this means is that we would be using “yo” CLI for creating an Asp.Net project (those of you coming from Visual Studio background: this is same as [File->New Project] that we did in Visual Studio).
Step 5: Create an Empty Web Application
Follow the following steps to create a web application (in terminal window) with basic project files and packages pre-configured:
navigate to the directory where you wish to create the project (using cd command), once inside the directory type the below command:
: yo aspnet
This will bring up the aspnet generator options, select “Web Application Basic [Without Membership and Authorization]”, once selected you would need to define the following for your application:
- UI Framework: Select Bootstrap (whatever version is available).
- App Name: name of your web application.
Once completed type the following commands to build and run your web application:
: cd “[your web application name]”
: dotnet restore
: dotnet build
: dotnet run
This would restore the packages, build your applications and run the application in Kestral web server.
This should bring up information about your web application such as url and port number (mine is localhost:5000) and you can navigate to the default page in a browser which looks like.
This is the same empty application that you get in Visual Studio when you fire up [File -> New Project].
In the next postย we would be discussing about opening and editing your newly created web application using Visual Studio Code and then subsequently creating a useful web application (I have an idea or two lets see which one I am going to choose).
See you soon with next steps.
Until then…
Pradeep
Leave a Reply