How to run an exe with Parameters in a task in Azure Devops?

Viewed 2539

I would like to know if we have a way to run an exe in Azure devops and passing required parameters for that. I am using below task "PowerShell" and it gives me the error

**

"C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a_temp\5f91c58a-381d-4c41-9969-3038116adefa.ps1'" & : The term 'MyProject.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At D:\a_temp\5f91c58a-381d-4c41-9969-3038116adefa.ps1:5 char:3"

**

Below is the task created in YAML.

- task: PowerShell@2
  displayName: Execute .exe file with parameters
  inputs:
    targetType: 'inline'
    script: |
      [String]$myrev = $Env:BUILD_BUILDNUMBER
      $args = @($myrev)
      & 'MyProject.exe' $args

Thanks in advance for the responses.


Little more info, tried to access the path where the build is created. Before accessing the path to run the exe, we are building the project and is kept at the default Azure Build Directory. Still same error but with full path.

- task: MSBuild@1
  inputs:
    solution: '**/*.csproj'
    clean: true

- task: PowerShell@2
  displayName: Execute .exe file with parameters
  inputs:
    targetType: 'inline'
    script: |
      [String]$myrev = $Env:BUILD_BUILDNUMBER
      $args = @($myrev)
      & '$(Build.SourcesDirectory)\MyProject\bin\Release\MyProject.exe' $args 
2 Answers

Are you sure your application is accessible in the current path? Check your folder content:

trigger:
- master

pool:
  vmImage: windows-2019

steps:
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      & cmd /c dir . 
    

Update:

Your solution should work. The tested example:

trigger:
- master

pool:
  vmImage: windows-2019

steps:
- task: VSBuild@1
  inputs:
    solution: 'ConsoleApp\ConsoleApp.sln'
    platform: 'Any CPU'
    configuration: 'Release'
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      [String]$myrev = $(Build.BuildNumber)      
      $args = @($myrev)
      & '$(Build.SourcesDirectory)\ConsoleApp\ConsoleApp\bin\Release\ConsoleApp.exe' $args 

Build result:

enter image description here

Check your path here:

enter image description here

Related