3

My project was created via dotnet new webapi --name=ProjectName. I've setup a build definition in VSTS. The Deployment to Azure runs fine, but I can't figure out how to run my migrations, i.e., dotnet ef database update

I've reviewed several of the other Stack Overflow questions. Though helpful, none of them provided a current solution. References:

The closest I've come to being successful is adding tasks like so:

  • Replace Tokens: Update Connection String
  • Command Line: set ASPNETCORE_ENVIRONMENT=Production
  • Command Line: dotnet ef database update -v

This almost works, but for some reason ef still targets development.

Any recent solutions?

dapperdan1985
  • 3,132
  • 2
  • 15
  • 26
  • 1
    Can you share the detail log on the OneDrive? (set system.debug variable to true, then queue build and share this log) Try to add variable ASPNETCORE_ENVIRONMENT and specify Production value then try again. – starian chen-MSFT Mar 14 '18 at 03:13
  • @starianchen-MSFT. Awesome! Adding ASPNETCORE_ENVIRONMENT to my variables worked. I had also looked at this question: https://stackoverflow.com/questions/44690138/vso-ci-aspnetcore-environment-is-set-to-production-no-matter-what-i-do which led me to believe that your recommendation wouldn't work, but I was pleasantly surprised. Thanks! – dapperdan1985 Mar 14 '18 at 14:06
  • Great! I post an answer that you can [accept it as answer](https://stackoverflow.com/help/someone-answers). On the other hand, another thread's issue is different, it runs the app on azure but you call dotnet ef command during build/release that the environment is on build/release agent. – starian chen-MSFT Mar 15 '18 at 02:12

1 Answers1

2

Adding ASPNETCORE_ENVIRONMENT variable to build/release definition and specify Production value.

starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53