In this post, I’ll cover how I got started, first installing the prerequisites and then workarounds I used while following Microsoft documentation. At the conclusion of this post, you’ll have achieved the same outcome as this Microsoft “Getting Started” tutorial (https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/?view=aspnetcore-3.1), but without having to deal with some of the shortcomings common in tutorials, such as the inconveniences and lack of support in Entity Framework for SQLite. This part of the journey was fairly straightforward. Following the tutorial was perfectly fine. The deviations I’ve outlined in this post helped me move beyond a ‘tutorial-grade’ solution and get to a codebase more well-suited to tackle the subject matter covered in future parts of this blog series.
Assuming you’re starting from scratch, you’ll need to have the .NET SDK installed, and you’ll likely want to have node/npm installed in a manageable way as well.
I’m a homebrew person myself. I installed the .NET SDK using this formula: https://formulae.brew.sh/cask/dotnet-sdk and the
brew install dotnet-sdk command.
It’s easy to slowly acquire an out-of-control web of node dependencies over the course of many projects, just like it was with Ruby gems. For this reason, I prefer installing and managing node versions for each project using NVM: https://github.com/nvm-sh/nvm. Installing node isn’t mentioned in the Microsoft tutorial, but will be helpful in the subsequent posts in this series.
The Microsoft documentation for getting started takes you pretty easily through most of the steps regardless of the IDE you’re using or the database you’re planning on connecting to: https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/working-with-sql?view=aspnetcore-3.1&tabs=visual-studio . With a little creativity, and some help from Azure, you can follow the instructions that rely on SQL Server. The issue you’ll run into on MacOS is that there is no version of “SQL Server Express LocalDB” and the documentation suggests using SQLite. The problem with SQLite (as noted in the documentation in the ‘Working with a database’ section using the ‘Visual Studio Code/Visual Studio for Mac’ instructions) is that any Entity Framework migrations that include dropping or altering a column will fail when run against SQLite. This likely won’t be an issue in the short term, but more than likely will be in the long term.
Using Postgres: (https://npgsql.org/efcore)
Since I will eventually be deploying my app to Azure I will use Azure SQL (which can be done for less than $5/mo).
Using Azure: Assuming you have an Azure account, from the Azure Portal, Go to ‘Create a resource’ -> ‘New’ -> ‘Databases’ -> ‘SQL Database’
After choosing a subscription, resource group, and entering a name and (or creating) a server, THE COST OF THE TYPE OF DATABASE CAN VARY GREATLY! In the ‘Compute + storage’ section, click ‘Configure Database’.
Note that if you do not have an available server to configure your database on, you can configure one from the ‘Basics’ tab using the ‘Create new’ option under the ‘Server’ drop down. If you decide to create new, you are presented with a ‘New server’ dialog on the right side of your browser window. From there, you can choose a server name, admin account name and password.
I’ve been using the ‘Basic’ configuration, that includes 5 DTUs and 2GB of storage. That’s been consistently $5/mo. There may be cheaper options using serverless configuration. There are DEFINITELY more expensive options. The important thing is to make sure to understand what you’re signing up for and the potential expense.
I clicked ‘Next’ to get to the ‘Networking’ step and made no changes.
I clicked ‘Next’ to get to the ‘Additional Settings’ step and made no changes.
I clicked ‘Next’ to get to the ‘Tags’ page and made no changes.
I clicked ‘Create’ to complete the setup.
Now from the Azure Portal, you can navigate to ‘Home’ > ‘SQL databases’, and choose the database you just created. From there, you can do useful things like configure the firewall to use whitelisted IP addresses,
and you can retrieve your connection string. This is where I retrieved the connection string for my local appsettings.json file.
Now that we’ve got a solid foundation to work with, in the next post, I’ll cover swapping out default front-end frameworks and adding front-end dependency management and static asset packaging.
NOTE: It’s probably worth mentioning before we go further that I haven’t had great luck with Visual Studio for Mac (https://visualstudio.microsoft.com/vs/mac/). I have had much enjoyable experience with VS Code (https://code.visualstudio.com/) and Rider (https://www.jetbrains.com/rider/). For the rest of the posts in this series, if you see a screen shot of an IDE, it will be a screenshot of Rider.