7

I am writing a .NET Core and Entity Framework Core Application using Code-First Migrations.

I want to be able to deploy it to an Azure Web App using Visual Studio Team Services Build and Release Definitions

I want to be able to run the Database Migration as part of the Release Definition using the script

dotnet ef database update

I've done this via a Command Prompt action in the Release Definition

However I always get the message

No executable found matching command "dotnet-ef"

I've tried making sure that this command is running in the same directory as a .cproj file

I've also tried running a

dotnet restore 

as a previous command prompt task, and this gives an error

The folder 'C:\a\r1\a\Drop\s\src\xxxxx' does not contain a project to restore even though it does.

Has anybody tried to do a Code First Migration as part of a Team Services Release Definition step?

My other option was to run the migration as part of the Web Application itself but I wanted to run it via the Release process rather than run it in the Application.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
TimBunting
  • 484
  • 5
  • 18

1 Answers1

2

You need to use Hosted VS2017 agent instead of Hosted agent. My steps:

  1. Edit csproj file to add this code below and check in changes (Refer to .NET Command Line Tools article)

Code:

<ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" PrivateAssets="All" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
  </ItemGroup>
  1. Command line step/task (Tool: dotnet; Arguments: --version)
  2. Command line step/task (Tool: dotnet; Arguments: restore)
  3. Command line step/task (Tool: dotnet; Arguments: ef --version)
  4. Queue build with Hosted VS2017 agent.
starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53
  • 1
    In VSTS I have a Build Definition which gets the code from TFS, restores packages and builds and runs a 'dotnet publish'. I wanted the Build step to not be environment specific. I already have Hosted VS2017 for the Build Step. I then wanted the Release Definition to be environment specific and run the migration there. Unfortunately I can't see a way of connecting to Hosted VS2017 for the Release step. WHen I try 'dotnet --version' in the release definition I discovered that it was only at 1.0.0-preview2-1-003177 and so neither dotnet restore or dotnet ef commands were working. – TimBunting Apr 07 '17 at 07:26
  • @TimBunting Edit your release definition > Select a environment > Click Run on agent > Change Deployment queue in the right panel. The version should be 1.0.0. – starian chen-MSFT Apr 07 '17 at 08:45
  • You were quite right, I hadnt see in Release definition how to select an agent. – TimBunting Apr 18 '17 at 11:53