登录
首页 >  Golang >  Go问答

Azure Pipeline 在 go get 后无法执行命令

来源:stackoverflow

时间:2024-04-01 08:36:34 333浏览 收藏

来到golang学习网的大家,相信都是编程学习爱好者,希望在这里学习Golang相关编程知识。下面本篇文章就来带大家聊聊《Azure Pipeline 在 go get 后无法执行命令》,介绍一下,希望对大家的知识积累有所帮助,助力实战开发!

问题内容

我想使用 rsrc 在我的 azure devops 管道中的 windows go 应用程序中设置图标。 我想我错过了一些琐碎的事情,我的管道在 go get -u -v github.com/akavel/rsrc 之后找不到命令 rsrc

我的解决方法是使用 vcs 中的 rsrc.exe。

管道

- task: Go@0
    displayName: Install rsrc
    condition: eq(variables['agent.os'], 'Windows_NT')
    inputs:
      command: 'get'
      arguments: '-u -v github.com/akavel/rsrc'
      workingDirectory: $(System.DefaultWorkingDirectory) 


  - task: PowerShell@2
    displayName: Generate syso files
    timeoutInMinutes: 1
    condition: eq(variables['agent.os'], 'Windows_NT')
    inputs:
      targetType: 'inline'
      script: |
        $icon = ([System.IO.Path]::Combine("$(System.DefaultWorkingDirectory)", "build/App.ico"))
        $iconSyso = ([System.IO.Path]::Combine("$(System.DefaultWorkingDirectory)", "cmd/myapp/rsrc.syso"))
        rsrc.exe -ico $icon -o $iconSyso
      workingDirectory: $(System.DefaultWorkingDirectory)

错误

rsrc.exe:术语“rsrc.exe”不被识别为 cmdlet、函数、脚本文件或可操作程序的名称。 检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。

更新

  1. go 安装 github.com/akavel/rsrc 没有帮助
  2. $env:gopath 为空

解决方案


我已经重现了您的错误:

我解决这个问题的方法是:

首先,在运行go任务之前,您应该提前设置gopathgobin

这是一个示例。

variables:
  gobin:  '$(gopath)\bin' # go binaries path
  gopath: '$(system.defaultworkingdirectory)\gopath' # go workspace path
  modulepath: '$(gopath)\src\github.com\$(build.repository.name)' # path to the module's code

然后将 gobin 添加到 path

- script: echo '##vso[task.prependpath]$(gobin)'

所以完整的脚本应该是这样的:

variables:
  GOBIN:  '$(GOPATH)\bin' # Go binaries path
  GOPATH: '$(System.DefaultWorkingDirectory)\gopath' # Go workspace path
  modulePath: '$(GOPATH)\src\github.com\$(build.repository.name)' # Path to the module's code

steps:
- task: Go@0
  displayName: Install rsrc
  condition: eq(variables['agent.os'], 'Windows_NT')
  inputs:
    command: 'get'
    arguments: '-u -v github.com/akavel/rsrc'
    workingDirectory: $(System.DefaultWorkingDirectory) 

- script: echo '##vso[task.prependpath]$(GOBIN)'

- task: PowerShell@2
  displayName: Generate syso files
  timeoutInMinutes: 1
  condition: eq(variables['agent.os'], 'Windows_NT')
  inputs:
    targetType: 'inline'
    script: |
      $icon = ([System.IO.Path]::Combine("$(System.DefaultWorkingDirectory)", "build/App.ico"))
      $iconSyso = ([System.IO.Path]::Combine("$(System.DefaultWorkingDirectory)", "cmd/myapp/rsrc.syso"))
      rsrc.exe -ico $icon -o $iconSyso
    workingDirectory: $(System.DefaultWorkingDirectory)

文中关于的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《Azure Pipeline 在 go get 后无法执行命令》文章吧,也可关注golang学习网公众号了解相关技术文章。

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>