The other day, I was glued to my PC, and I had spare time (yah, I know very unusual). Since .Net Core 1.0 was just released few days before, I decide to give it a try. To add an extra layer of fun in the mix, I decided to do it from my Ubuntu VM. In less than 15 minutes, everything was done! I was so impressed I knew I needed to talk about it. That's exactly what this post is about.
The preparation
Before we get started, it's important to know which version of Ubuntu you are using, because some commands will be slightly different. To know the version you are running you simply need to click the gear in the top right of the desktop screen and select About this Computer. In my case, since I'm using Ubuntu 14.04 LTS, I will be using command related to this version. If you are using a different version, please refer to .NET Core documentation.Now we need to install .Net Core. Nothing more easy. Open a Terminal (Ctrl+Alt+T) and type those three commands:
# Setup the apt-get feed adding dotnet as repo
sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list'
apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893
# Get the latest packages
apt-get update
# Install .NET Core SDK
sudo apt-get install dotnet-dev-1.0.0-preview2-003121
Once it's all done you can type dotnet --info
and you should see something like that.Create the Local WebApp
From the same Terminal we will create an empty folder for our solution and move into it. Execute these commands.mkdir demodotnetweb
cd demodotnetweb
We now want to create our new web project. This is done by the command dotnet new
, but we need to specify the type otherwise it will create a console application.dotnet new -t web
Now to download all the references (nuget packages) of our project required, execute the following command:dotnet restore
Base on the speed of your Internet connection and how many dependencies are required, this can take from few seconds to more than one minute.To test if our solution works locally type the command:
dotnet run
That will compile our solution and start an AspNetCore Internal hosting. Launch a web browser and go to http://localhost:5000 to see the App in action.Deploy to Azure
To deploy our new project to the cloud, we will use the continuous deployment capability of Azure. First, navigate to portal.azure.com and create a Web App.Once the the application is created, you should see the This web app as been created message when you navigate to the
[nameofWebApp].azurewebsites.net
It's now time to add a local Git repository. In the WebApp Settings select Deployment source. Click on the Configure Required Settings, then select the Local Git Repository option.
After setting the user credential for the repository, we can get the URL from the Essential section.
Back to our Ubuntu Terminal, we will have to execute these commands:
# create a git repository
git init
# commit all files
git commit -m "Init"
# Add the remote repository
git remote add azure https://username@demowebcore.scm.azurewebsites.net:443/demowebcore.git
# Push the code to the remote
git push azure master
After a minute or so you should have your WebApp online!Voila! That was fun!.