We are trying to generate SQL scripts for the migrations dotnet ef migrations script {...} as part of the build process but there doesn't seem to be a way of dealing with them at the moment (other than using visual studio). I might be missing something here but both vso build agents and azure apps are unable to apply migrations so I'm wondering how to do it as part of the CI/deployment pipeline.
Thanks
What do you do locally on your dev box on the command line? And does that work?
Locally I can run dotnet ef {any command} and it works fine.
What version of VS is installed? What version of dotnet is installed? What is the log output when you run it as part of the CI build?
Visual studio 2015 Update 3 and dotnet 1.0.0-preview2-003131
Running as part of the CI build gives me this: No executable found matching command "dotnet-ef" .The offending build step is just a command line executing "dotnet ef migrations {etc}"
Not sure if this is really relevant to the case but here's the project.json:
{
"dependencies": {
"Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
"Microsoft.AspNetCore.Identity": "1.0.0",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.EntityFrameworkCore": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"Microsoft.EntityFrameworkCore.Design": {
"type": "build",
"version": "1.0.0-preview2-final"
},
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Sendgrid": "8.0.3"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"net461": {
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true,
"compile": {
"exclude": [
"node_modules",
"jspm_packages"
]
}
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"prepublish": [ "npm install", "gulp build" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Have you restored your nuget packages?
@srfabio ?
I'm sorry for the delay. Yes we did restore nuget as the first build step but that didn't solve the problem.
However, looks like we solved it by changing the working folder to 'src/{project}' on the command line step.
Thanks
Thanks for following up.
Hi @srfabio
can you please explain how you use the script to apply a migration from VSTS?
Thanks!
Hi @bragma
I don't have access to the code or VSTS anymore but essentially we've used the script to generate SQL files as part of the build process and then on the Release definition we had a step that would deploy/execute those scripts on our Azure database. That was the only way we could deploy migrations on azure.
Hope this helps (sorry for the lack of detail)
@srfabio thanks it's what I expected. I was looking for an official way for handling migrations in Azure when deploying from VSTS.
I still can't get this to work. Very frustrating. I have a script after deployment is done that is supposed to run
dotnet ef database update
and it blows up the build with
No executable found matching command "dotnet-ef"
I even included a line in my csproj file like so:
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.2" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.2" />
</ItemGroup>
...but it seems to be ignored.
@jholovacs That's the error I had before, I only needed to change the working folder path to src/{project_name} to make it work.
@srfabio It doesn't work, still have the same error
(#&%$(#&$! I'm dealing with this too!
I had the same problem.
But changing the build definition to something like the following works:
- task: DotNetCoreCLI@2
displayName: 'Generate EF Migrations script'
inputs:
command: custom
custom: 'ef'
arguments: 'migrations script --project $(project) --output $(Build.ArtifactStagingDirectory)/SQL/$(scriptName) --context $(dbContext) --idempotent'
It looks like the dotnet Core custom build task puts a dash between the dotnot executable and the custom command contains spaces. This seems like a bug.
Please reopen this issue.
I had the same issue exactly in Azure Pipelines and finally this is my solution:
Command Line step:
steps:
- script: '$env:ASPNETCORE_ENVIRONMENT='Development''
displayName: 'Set DB Environment'
Command Line step: (also define working directory of project)
steps:
- script: 'dotnet-ef database update --project $(project)'
workingDirectory: TunelHelperApi
displayName: 'Database Update'
continueOnError: true
Most helpful comment
Visual studio 2015 Update 3 and dotnet 1.0.0-preview2-003131
Running as part of the CI build gives me this:
No executable found matching command "dotnet-ef".The offending build step is just a command line executing "dotnet ef migrations {etc}"