Random failures in build pipelines when running dotnet-ef

230 Views Asked by At

As part of build I need to generate db migration script. I'm using Microsoft provided build agent

(only interesting part below)

pool:
  vmImage: 'windows-2019'

- task: DotNetCoreCLI@2
      displayName: Install dotnet-ef
      inputs:
        command: 'custom'
        custom: 'tool'
        arguments: 'install dotnet-ef -g --version 5.0.0-preview.8.20407.4'

    - task: DotNetCoreCLI@2
      displayName: Generate migrations sql script
      inputs:
        command: 'custom'
        custom: 'ef'
        arguments: 'migrations script --project Web/Dal --startup-project Web/WebApi --configuration $(buildConfiguration) --context EmailContext --no-build --output $(Build.ArtifactStagingDirectory)/emailcontext-migrations.sql --idempotent --verbose'

dotnet-ef installation seems to work fine: Tool 'dotnet-ef' (version '5.0.0-preview.8.20407.4') was successfully installed.

but it still fails from time to time with (more often recently) :

"C:\Program Files\dotnet\dotnet.exe" ef migrations script --project Web/Dal --startup-project Web/WebApi --configuration Release --context EmailContext --no-build --output D:\a\1\a/emailcontext-migrations.sql --idempotent --verbose
Could not execute because the specified command or file was not found.

Is there a problem with my build pipeline configuration?

2

There are 2 best solutions below

1
On

If it fails from time to time I would rather say that this can be an issue with preview version.

Please add an next step after installing to list all globally installed tools:

dotnet tool list -g

You may also show us a log of installing tool for case when your pipeline doesn't work. To verify if you have this:

enter image description here

(We simply don't know it, since we can't check your logs).

And if it still happens I would encourage you to create an issue on GitHub.

2
On

From your description, this is an intermittent issue. So your pipeline configuration could be correct.

Could not execute because the specified command or file was not found.

This issue seems to be related to the dotnet-ef package installed.

As Krzysztof Madej's suggestion, this package version could cause this issue.

You could try to use the latest version: 5.0.0-rc.1.20451.13 or latest stable version: 3.1.8.

Here is a GitHub ticket with the same issue( Can't find the file after global installing dotnet-ef). You could follow it and check the update.

On the other hand, you could try to use the Command Line Task to install the dotnet-ef.

For example:

  - task: CmdLine@2
    inputs:
      script: 'dotnet tool install --global dotnet-ef  --version xxxx'