There are also many moving parts that they needs to be aware of when building an application that many other stacks abstract away.
- Entity Framework
- Code-first Modeling
- View Models
- Model Binding
- Razor Templating
- View Components
On top of that, they have to learn the concepts of OOP, relational data concepts, ERDs, agile workflow, being a good teammate, etc. It’s a significant amount of knowledge for them to gain a slim understanding of in 60 days.
One thing that has made teaching the course easier is Microsoft’s wholehearted adoption of the open source, cross platform mindset once Satya Nadella took the reins of the company. I walked away from the Microsoft world back in 2011 because it was a mess. It was tough, because I absolutely love the C# language, but the ecosystem was too bloated, locked into the Windows OS, and notoriously hard to manage.
Now that .NET Core is out, and much more mature with 2.0, I’m as happy as a fox in a hen house. I can start the students coding in C# on day 1 because they can install .NET Core SDK, Visual Studio Code, and SQLite and immediately start learning. Windows does get installed as a VM on all their machines over the first couple weeks of the course, since they do need to gain some comfort with the OS, SQL Server, and Visual Studio Community Edition, but they are no longer required - which is both exciting, and a bit strange.
While I’m talking strange, I recently went through the process of deploying a small, sample ASP.NET MVC application to my Ubuntu VPS on Digital Ocean so that students could deploy their applications likewise and not have to worry about Azure deployment while they are looking for jobs. The fact that I can even type that sentence now feels odd.
I want to share that knowledge with the community.
RUNNING ASP.NET ON LINUX
Azure is Microsoft’s cloud platform, and an option for deploying their code. However, since we are teaching .NET Core, and its whole philosophy is to be cross platform, I decided to find out how to deploy my example ASP.NET web application to my own Linux VPS on Digital Ocean with Nginx as the reverse proxy to the running
dotnet assembly. The process was surprising straightforward and made me wonder at this brave, new world that we live in where running a .NET project on Linux is easy, and intended.
Here’s what you need to do. I’m going to make the assumption that you already have a VPS, or EC2 instance (or equivalent) running that you can deploy to.
- Get .NET Core installed on the machine.
- Clone your repository to a directory of your choosing on your machine.
dotnet restoreto install required packages.
dotnet ef database updateto create your database. Since this is Linux, unless you are using RHEL, you’ll have to stick to SQLite or MySQL - basically anything but SQL Server as your engine.
dotnet runto verify that the build works and go to your domain on port 5000 to test that it works as intended. Make sure you open up port 5000 on your firewall temporarily to test it.
- If your application builds, and works, then it’s time to start configuring your system to run it as a service. First, create a new
Arecord on your domain so that your application will run as a sub-domain if you like.
- The folks at Microsoft put together a wonderful guide for setting up Nginx configuration, service configuration, and publishing your application. Read the ASP.NET Core on Linux with Nginx. Here’s a quick highlight of those steps.
dotnet publishto package up your application into a production assembly.
- Create a new
sites-availableconfiguration file. I made
/etc/nginx/sites-available/commercebecause I’m running a sub-domain - commerce.bangazon.com.
- Create a symlink of your new config file to sites-enabled with
ln -s /etc/nginx/sites-available/commerce /etc/nginx/sites-enabled/commerce.
- Reload nginx configuration with
nginx -s reload.
- Create the systemctl config file for your dotnet process.
- Enable the service (e.g.
systemctl enable commerce.service).
- Start the service (e.g.
systemctl start commerce.service).
- Check the status of the service (e.g.
systemctl status commerce.service).