Azure-pipelines-tasks: dotnet ef is failing in Azure DevOps Pipeline when the agent is ubuntu-latest

Created on 18 Mar 2020  路  5Comments  路  Source: microsoft/azure-pipelines-tasks

Bug

I am trying to run dotnet ef command within Azure DevOps Pipeline and it's failing with the error: Could not execute because the specified command or file was not found..

Note: I am installing the tool in the first task and then I am checking the version.

trigger:
- master

resources:
- repo: self

variables:
  vmImageName: 'ubuntu-latest'

stages:

- stage: Build
  displayName: Build and push stage
  jobs:  
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
    steps:
    - task: DotNetCoreCLI@2
      displayName: Install dotnet-ef
      inputs:
        command: 'custom'
        custom: 'tool'
        arguments: 'install --global dotnet-ef --version 3.1.1 --ignore-failed-sources'
    - task: DotNetCoreCLI@2
      displayName: Check dotnet-ef version
      inputs:
        command: 'custom'
        custom: 'ef'
        arguments: '--version'

Logs:

Task: Install dotnet-ef

Starting: Install dotnet-ef
==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version      : 2.166.2
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
/usr/bin/dotnet tool install --global dotnet-ef --version 3.1.1 --ignore-failed-sources

Welcome to .NET Core 3.1!
---------------------
SDK Version: 3.1.101

Telemetry
---------
The .NET Core tools collect usage data in order to help us improve your experience. The data is anonymous. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.

Read more about .NET Core CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry

----------------
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Find out what's new: https://aka.ms/dotnet-whats-new
Learn about the installed HTTPS developer cert: https://aka.ms/aspnet-core-https
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli-docs
Write your first app: https://aka.ms/first-net-core-app
--------------------------------------------------------------------------------------
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.1.1') was successfully installed.
Info: Azure Pipelines hosted agents have been updated to contain .Net Core 3.x SDK/Runtime along with 2.2 & 2.1. Unless you have locked down a SDK version for your project(s), 3.x SDK might be picked up which might have breaking behavior as compared to previous versions. 
Some commonly encountered changes are: 
If you're using `Publish` command with -o or --Output argument, you will see that the output folder is now being created at root directory rather than Project File's directory. To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
Finishing: Install dotnet-ef

Task: Check dotnet-ef version

Starting: Check dotnet-ef version
==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version      : 2.166.2
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
/usr/bin/dotnet ef --version
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
Info: Azure Pipelines hosted agents have been updated to contain .Net Core 3.x SDK/Runtime along with 2.2 & 2.1. Unless you have locked down a SDK version for your project(s), 3.x SDK might be picked up which might have breaking behavior as compared to previous versions. 
Some commonly encountered changes are: 
If you're using `Publish` command with -o or --Output argument, you will see that the output folder is now being created at root directory rather than Project File's directory. To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
##[error]Dotnet command failed with non-zero exit code on the following projects : 
Finishing: Check dotnet-ef version

However when the agent is windows-2019, it is working.

Clones: https://github.com/dotnet/sdk/issues/10894

Release question

Most helpful comment

@vineetmimrot, Thank you very much for your reply. And extremely sorry for the delay.

And yes, I just tried using UseDotNet@2 first to install the dotnet sdk and below works.

trigger:
- master

resources:
- repo: self

variables:
  vmImageName: 'ubuntu-latest'

stages:

- stage: Build
  displayName: Build
  jobs:  
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
    steps:
    - task: UseDotNet@2
      inputs:
        version: '3.1.200'
    - task: DotNetCoreCLI@2
      displayName: Install dotnet-ef
      inputs:
        command: 'custom'
        custom: 'tool'
        arguments: 'install --global dotnet-ef'
    - task: DotNetCoreCLI@2
      displayName: Check dotnet-ef version
      inputs:
        command: 'custom'
        custom: 'ef'
        arguments: '--version'

Thanks for the hint on not specifying EF version 馃憤

All 5 comments

Hey @jaliyaudagedara,
You should use the UseDotnet@2 task, to install the dotnet sdk (preferably latest version i.e. 3.1.200) and then install the dotnet ef with what you have mentioned in the problem description. This will make dotnet-ef installed into same path as of dotnet sdk and will make it able to execute.

Also as per this issue https://github.com/dotnet/efcore/issues/15448, you should not mention the ef version and let the dotnet tool install the appropriate ef version as per the sdk installed.

Please re-open it, if you face any issues.

@vineetmimrot, Thank you very much for your reply. And extremely sorry for the delay.

And yes, I just tried using UseDotNet@2 first to install the dotnet sdk and below works.

trigger:
- master

resources:
- repo: self

variables:
  vmImageName: 'ubuntu-latest'

stages:

- stage: Build
  displayName: Build
  jobs:  
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
    steps:
    - task: UseDotNet@2
      inputs:
        version: '3.1.200'
    - task: DotNetCoreCLI@2
      displayName: Install dotnet-ef
      inputs:
        command: 'custom'
        custom: 'tool'
        arguments: 'install --global dotnet-ef'
    - task: DotNetCoreCLI@2
      displayName: Check dotnet-ef version
      inputs:
        command: 'custom'
        custom: 'ef'
        arguments: '--version'

Thanks for the hint on not specifying EF version 馃憤

@vineetmimrot @jaliyaudagedara Thank you both for reporting and solving this issue here. I almost lost a day trying to make it work out. The issue with me was i didnt install dotnetsdk.

Hey @jaliyaudagedara,
You should use the UseDotnet@2 task, to install the dotnet sdk (preferably latest version i.e. 3.1.200) and then install the dotnet ef with what you have mentioned in the problem description. This will make dotnet-ef installed into same path as of dotnet sdk and will make it able to execute.

Also as per this issue dotnet/efcore#15448, you should not mention the ef version and let the dotnet tool install the appropriate ef version as per the sdk installed.

Hi @jaliyaudagedara, i did what you propose and it works, but why do we need to use the UseDotNet task ? I use microsoft hosted agent (https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md#net-core-sdk), so the .net core SDK 5.0.100 is already install, so why we have to install the same .net core SDK by using the task UseDotNet ?

Was this page helpful?
0 / 5 - 0 ratings