1

I'm trying to create an Entity Framework Migration script from my Azure Build Pipe Line.

I have the following two steps. The first step installs version 3.0.0 of dotnet-ef (I'm using .NET Core 3.0). The second step tries to generate the script which is failing and I can't work out why. It seems to work when the Agent Specification is set to "windows-2019" but not "ubuntu-18.04". Does anyone know why this may be the case?

STEP 1

==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version      : 2.158.1
Author       : Microsoft Corporation
Help         : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
/usr/bin/dotnet tool install --global dotnet-ef --version 3.0.0
Since you just installed the .NET Core SDK, you will need to logout or restart your session before running the tool you installed.
You can invoke the tool using the following command: dotnet-ef
Tool 'dotnet-ef' (version '3.0.0') was successfully installed.
Finishing: dotnet-ef tool install

STEP 2

==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version      : 2.158.1
Author       : Microsoft Corporation
Help         : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
/usr/bin/dotnet ef migrations script --idempotent --project /home/vsts/work/1/s/blah1.csproj --startup-project /home/vsts/work/1/s/blah2.csproj --output /home/vsts/work/1/a/migrations/BlahContext.sql --context BlahContext
Could not execute because the specified command or file was not found.
Possible reasons for this include:
  * You misspelled a built-in dotnet command.
  * You intended to execute a .NET Core program, but dotnet-ef does not exist.
  * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
##[error]Error: The process '/usr/bin/dotnet' failed with exit code 1
##[error]Dotnet command failed with non-zero exit code on the following projects : 
Finishing: Generate RnhContext Migration Scripts
PatrickNolan
  • 1,671
  • 2
  • 20
  • 40
  • I assume dotnet-ef is installed globally, can you try to run "./dotnet-ef ......" – Vova Bilyachat Nov 20 '19 at 01:21
  • Hi @VolodymyrBilyachat I'm using the .NET Core build step which doesn't allow this to be set. In any case it works when the build Agent Specification is set to "windows-2019". https://learn.microsoft.com/en-gb/azure/devops/pipelines/ecosystems/dotnet-core?view=azure-devops – PatrickNolan Nov 20 '19 at 05:21
  • Just checking in to see if the information provided was helpful. Please let us know if you would like further assistance. – Leo Liu Nov 28 '19 at 06:00

1 Answers1

2

How to create Entity Framework Migration script from Azure Build Pipe Line?

I could reproduce this issue on agent ubuntu-18.04 with command line task.

Since I am not familiar with the dotnet ef migration script, I use the command line dotnet ef instead. Now, I got the same issue:

enter image description here

After a period of investigation, I found I need add a line to your shell's configuration before I execute the command dotnet ef:

export PATH="$PATH:$HOME/.dotnet/tools/"

So, my command line looks like:

enter image description here

As test, it works fine on the agent ubuntu-18.04:

enter image description here

Check the related ticket for some more details.

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135