Dotnet Core
Dotnet Core Entity Framework Migrations on Cloud Foundry
Run database migrations on Cloud Foundry using a task to ensure that migrations are only done once on deployment (and not during app start up!) for dotnet core applications. This post assumes you are deploying built applications and not raw source code.
Instead of depending on dotnet tooling (dotnet-ef
), leverage the built-in migration capability of the DataContext. Interrupt the startup procedure when a special argument is passed in, instead of starting the web application, run the migrations and then exit.
So here we go, to start we need a DbContext:
Dotnet core 5 on a raspberry pi
Here’s a quick get-up-and-go style post on how to get dotnet core 5 usable on a Raspberry Pi (a R-Pi 3 Model B in my case).
We’re doing all this over SSH because my goal was to run a small webapp on the Pi which is located in a cupboard somewhere in my house without a keyboard and mouse attached to it 😁 So, after you’ve connected to the Pi over SSH, the first step is to install the dotnet core SDK.
Environment variables in an Azure Web App for Containers
Here’s a little gotcha I ran into. A .net core app I wrote needs to run inside a container and the target was a Web App for Containers on the Azure platform. No big deal so far.
The app also needs a few settings for it to do its work. We provide these via environment variables for maximum flexibility. After setting up some CI/CD stuff and deploying the app it wouldn’t start because it wasn’t loading the settings.
ASP.NET Core logging on Cloud Foundry
All apps I’ve ever worked on have some sort of logging going on for various reasons, mostly to keep track of whats going on or debugging, but it’s all the same. Logs are needed to see what your code is up to.
Cloud Foundry is very explicit about how an app should write its logs. As you can see in the documentation, apps must write to stdout
or stderr
.
For C# that means we can use the static methods on the Console
to write our logs. Couldn’t be easier. But… now our code is littered with these Console.Write...
lines all over the place!
Angular (5) and aspnet core (2) quickstart
Here is a get-up-and-go style post to get going with the angular CLI and aspnet core. Before we begin, there is a template you can use to set (most, if not more) of this up, but it’s good to know what is going on behind the curtains.
First things first.
You need some tools installed to get the base project set up.
- dotnet core SDK
- Node
- angular-cli which we’ll install using NPM.
Open a command prompt and run the following command:
Dotnet Core CLI user secrets
User secrets are what you use for settings in a .NET Core app that you don’t want committed to your public repos (think API keys, passwords, anything sensitive). You map out your actual settings and they override them with the values from the secrets, which are stored outside of the tracked source folder.
On windows the user secrets folder is located here: %APPDATA%\microsoft\UserSecrets
. Let’s have a look at how use them with the new tooling for .NET Core that came out recently.
Dotnet Core tooling quickstart
With the .NET Core tools finally showing signs of stabilizing in version 1.0.1 we can have a little look at how you can get started with a new project using just the tools.
You can download the new stuff here. I’m writing this post using the 1.0.1 version of the tools.
A new very nice thing is that the new tooling comes with some built in templates you can use instead of relying on something like Yeoman to create an empty project for you. The dotnet new
command is still the way to create a new project (like it was in the older tools) but you can now specify what kind of project you want as a base.
My first ASP.NET Core app on Cloud Foundry
Today I tried to deploy a .NET Core web app to a Pivotal Cloud Foundry platform that my ITQ buddy Ruurd set up for us to tinker with. The app itself is a very basic ASP.NET MVC app built with the new ASP.NET Core framework to make it cross-platform. It being cross platform makes it very easy to deploy on something like Cloud Foundry since there is no dependency on Windows or the full .NET Framework anymore.