Migrating databases with EF Core 2.0 during a VSTS release

A while ago I wrote down how to migrate a database using the default tooling with EF Core 1.1. With 2.0 being released last August it was finally time to upgrade projects on which I’m working to the latest bits. A reader had already reported that the same approach as used with 1.1 no longer worked for EF Core 2.0.

Again I ran the update database command with the verbose option and I saw that the command itself has not changed. What has changed however is the location of EF.dll. Even when forcing the package restore to not use any caching and explicitly stating where the packages had to be installed, EF.dll just would not show up. It is however located (at least on my Mac) at /usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.entityframeworkcore.tools.dotnet/2.0.0/tools/netcoreapp2.0/ef.dll.

I tried for an hour or two to get this file in a zip archive on Windows and on macOS. The easy way out would be to just find the dll and add it to source control. Of course I went for another solution: download the EF.dll during a release and use it to update the databases.

I edited the release definition of VSTS and in my first attempt I tried to use the package management task which you get when you install this extension. Unfortunately this is not meant to be used to download public packages from the NuGet servers.

Second attempt was to use the Download file task. It was not able to download the NuGet package I needed giving me a 404 error.

So when everything fails, Powershell will fix it. With just a single line I was able to download the NuGet package containing EF.dll.

I used an inline script, but you could just create a script and add it to source control so you can use variables for the package name.

wget "https://www.nuget.org/api/v2/package/Microsoft.EntityFrameworkCore.Tools.DotNet/2.0.0" -outfile "EF.nupkg"

Then I extract all the files, since the build output contains one or more zip files and a nupkg file is also just a zip archive. My sample project just contained one zip.

Then move the EF.dll to the location where the assembly resides containing the DbContext and migrations. The final step is to execute the update command.

mv ./tools/netcoreapp2.0/ef.dll ./
dotnet exec --depsfile migratetest20.deps.json  --runtimeconfig migratetest20.runtimeconfig.json ef.dll database update --assembly migratetest20.dll --startup-assembly migratetest20.dll

Migratetest20 was my test project.

Topconf Duesseldorf 2017

Last week I was fortunate enough to be part of Topconf Duesseldorf. It was the first time the conference was organized in Duesseldorf. My talk on blockchain technology and more specific on Bitcoin and Ethereum had been selected and together with 46 other speakers we would fill two days packed with sessions.

I had changed the abstract a little bit after reviewing the feedback from NDC and also removed parts of the presentation to fit it in 40 minutes. In the end though I did go over time, and with only 10 minutes between sessions I had to rush through the last part. Lessons learned for next month when I will be giving this talk at Topconf Talinn.

There were a lot of questions during and after the talk so the audience was quite engaged, in fact the atmosphere of the entire conference was very amicable. The reviews which have been submitted for my session also reflect my own thoughts on how it went. At the time of writing this post my session got an average score of 4.29 / 5. The slides can be downloaded here and the code of the DApp is available on GitHub. I’ve now written the game 3 times and it was also the first time I felt confident enough to let the attendees participate.

In the audience was also Joy Clarck who made a great summary.