I finally got to fix it.
There are two solutions I found to fix the issue.
- First, there's a common fix for all the databases that support Entity Framework Migrations:
- Using a .NET Core Task, we'll have to install the dotnet ef tool:
The task would look like this:
And this would be the YAML (in case you want to use it in out of the release pipeline):
- task: DotNetCoreCLI@2
displayName: 'dotnet custom'
inputs:
command: custom
custom: tool
arguments: 'install --global dotnet-ef --version 3.1.4 --ignore-failed-sources'
- And once we have the required tools installed, with a CMD or a Bash Task, we'll have to execute a script like this:
dotnet ef database update -c <DBCONTEXT> -p <PROJECT> -s <STARTUP_PROJECT> -v --no-build
You just have to add the flag -c in case you have more than one context in your project (sometimes the other DbContexts can come from some nugget packages).
Notice I added the flag --no-build since I already built the project in the build pipeline to follow good practices.
- The other option (and the one I finally used), it's been to use this task that basically does the same process, with the difference that it does it by using your already compiled .dll files, so you won't have to copy the entire project to make the migrations work. The setup of the task, although you have to fill many inputs, it's pretty straightforward, and it's supposed to work with other Databases as well.
However, if I had to use SQL Server or MySQL I would use a migrations script, since the process it's much easier (you just need to generate a .sql script and then it's the only file required for deploying the migrations).
dotnet ef database update
command and it worked (after first installing the 'dotnet ef tools' in my agent). However I ended up using this task, which it worked as well, although not with migration scripts as the ones I mentioned above. – Ferran R.