在 Azure DevOps 的 Windows pipeline 中生成 Go 的 syso 文件的步骤
偷偷努力,悄无声息地变强,然后惊艳所有人!哈哈,小伙伴们又来学习啦~今天我将给大家介绍《在 Azure DevOps 的 Windows pipeline 中生成 Go 的 syso 文件的步骤》,这篇文章主要会讲到等等知识点,不知道大家对其都有多少了解,下面我们就一起来看一吧!当然,非常希望大家能多多评论,给出合理的建议,我们一起学习,一起进步!
我想使用 go build 的 syso 文件为我的可执行文件设置图标。
在我的 win10 笔记本上一切正常,但是当我在 ubuntu-latest 或 windows-latest 中使用相同的 syso 文件(使用 git lfs 签入)时,我收到以下消息:
c:\users\vssadm~1\appdata\local\temp\go-build430615882\b001\_pkg_.a(rsrc.syso): not an object file ##[error]the go task failed with an error: error: the process 'c:\hostedtoolcache\windows\go\1.14.2\x64\bin\go.exe' failed with exit code 2
对于我的问题,如何在 azure devops 上的 windows pipline 中生成 go 的 syso 文件并将其与 go build 一起使用?
pool:
vmImage: 'windows-2019'
variables:
GOBIN: '$(GOPATH)/bin'
GOPATH: '$(system.DefaultWorkingDirectory)/gopath'
ExecutableName: tool
GoFilePath: '$(System.DefaultWorkingDirectory)/cmd/Tool/'
steps:
- task: GoTool@0
inputs:
version: '1.14.2'
- task: Go@0
inputs:
command: 'get'
arguments: '-d ./...'
workingDirectory: '$(System.DefaultWorkingDirectory)'
- task: PowerShell@2
displayName: Set last tag to variable
inputs:
targetType: 'inline'
script: |
$VERSION_TAG = git describe --tags (git rev-list --tags --max-count=1)
Write-Host("##vso[task.setvariable variable=VERSION_TAG]$VERSION_TAG")
Write-Host("##vso[build.addbuildtag]$VERSION_TAG")
Write-Host($VERSION_TAG)
- task: PowerShell@2
displayName: Set date to variable
inputs:
targetType: 'inline'
script: |
$DATE = Get-Date -Format "yyyy-MM-dd"
Write-Host("##vso[task.setvariable variable=DATE]$DATE")
- task: Go@0
displayName: 'Create release for windows x64'
enabled: true
env:
GOOS: windows
GOARCH: amd64
inputs:
command: 'build'
arguments: '-ldflags "-s -w -X main.Version=$(VERSION_TAG) -X main.BuildTime=$(DATE)" -trimpath -o release_build/$(ExecutableName).exe $(GoFilePath)'
workingDirectory: '$(System.DefaultWorkingDirectory)'
- task: Go@0
displayName: 'Create release for windows x86'
enabled: true
env:
GOOS: windows
GOARCH: 386
inputs:
command: 'build'
arguments: '-ldflags "-s -w -X main.Version=$(VERSION_TAG) -X main.BuildTime=$(DATE)" -trimpath -o release_build/$(ExecutableName)_x86.exe $(GoFilePath)'
workingDirectory: '$(System.DefaultWorkingDirectory)'
- task: Go@0
displayName: 'Create release for linux x64'
enabled: true
env:
GOOS: linux
GOARCH: amd64
inputs:
command: 'build'
arguments: '-ldflags "-s -w -X main.Version=$(VERSION_TAG) -X main.BuildTime=$(DATE)" -trimpath -o release_build/$(ExecutableName).bin $(GoFilePath)'
workingDirectory: '$(System.DefaultWorkingDirectory)'
- task: Go@0
displayName: 'Create release for linux x86'
enabled: true
env:
GOOS: linux
GOARCH: 386
inputs:
command: 'build'
arguments: '-ldflags "-s -w -X main.Version=$(VERSION_TAG) -X main.BuildTime=$(DATE)" -trimpath -o release_build/$(ExecutableName)_386.bin $(GoFilePath)'
workingDirectory: '$(System.DefaultWorkingDirectory)'
- task: Go@0
displayName: 'Create release for macOS x64'
enabled: true
env:
GOOS: darwin
GOARCH: amd64
inputs:
command: 'build'
arguments: '-ldflags "-s -w -X main.Version=$(VERSION_TAG) -X main.BuildTime=$(DATE)" -trimpath -o release_build/$(ExecutableName).app $(GoFilePath)'
workingDirectory: '$(System.DefaultWorkingDirectory)'
- task: CopyFiles@2
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)/release_build'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: CopyFiles@2
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)/docs'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'Tool Executables'解决方案
当我写这个问题时,我发现,我对这些文件使用 git lfs 。
添加此步骤后,我可以使用资源文件编译可执行文件。
steps: - checkout: self lfs: true
但是在针对 goos windows 进行构建之后,我必须删除这些文件,否则我会收到错误:
/opt/hostedtoolcache/go/1.14.2/x64/pkg/tool/linux_amd64/link: running gcc failed: exit status 1 /usr/bin/ld: i386 architecture of input file `/tmp/go-link-782633042/000000.o' is incompatible with i386:x86-64 output collect2: error: ld returned 1 exit status
删除这些文件的步骤:
- task: powershell@2
displayname: remove syso files
inputs:
targettype: 'inline'
script: |
remove-item $(system.defaultworkingdirectory)/cmd/analysetool/*.syso
说明
这是 v1 文本指针的示例:
version https://git-lfs.github.com/spec/v1 oid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393 size 12345 (ending \n)
来源:https://github.com/git-lfs/git-lfs/blob/master/docs/spec.md
下载源代码时不支持 lfs,将放置此文本文件而不是真实文件。
很明显,该文件无法执行(错误的幻数)或者引用的 bin 文件格式错误(不是目标文件)。
今天关于《在 Azure DevOps 的 Windows pipeline 中生成 Go 的 syso 文件的步骤》的内容介绍就到此结束,如果有什么疑问或者建议,可以在golang学习网公众号下多多回复交流;文中若有不正之处,也希望回复留言以告知!
修复golang嵌套模板的方法详解
- 上一篇
- 修复golang嵌套模板的方法详解
- 下一篇
- 主函数中设置Mongo客户端,其他模块接收nil值
-
- Golang · Go问答 | 16分钟前 |
- bufio.Scanner token too long 如何改用 Reader
- 196浏览 收藏
-
- Golang · Go问答 | 18分钟前 | Go问答 · 数据导入 · Go encoding/csv csv.Reader LazyQuotes ParseError 引号换行
- encoding/csv 遇到引号换行时的解析处理
- 307浏览 收藏
-
- Golang · Go问答 | 26分钟前 | Timer · Go问答 · Go 定时任务 截止时间 time.Ticker time.Timer 周期漂移
- Ticker 周期漂移时如何改成按截止时间调度
- 308浏览 收藏
-
- Golang · Go问答 | 26分钟前 | time · go · time.Parse ParseInLocation Go时区
- time.Parse 解析带中文时区为什么失败
- 222浏览 收藏
-
- Golang · Go问答 | 28分钟前 | Go问答 · encoding/json · 输入校验 · Go unmarshal encoding/json JSON重复键 JSON排查
- JSON 重复键解码时为什么只剩最后一个值?
- 439浏览 收藏
-
- Golang · Go问答 | 30分钟前 | 结构体 · api设计 · Go问答 · encoding/json · Go 结构体 dto encoding/json 未导出字段 json.Marshal MarshalJSON
- json.Marshal 为什么忽略未导出的字段
- 295浏览 收藏
-
- Golang · Go问答 | 34分钟前 |
- json.Number 如何避免大整数精度丢失
- 298浏览 收藏
-
- Golang · Go问答 | 35分钟前 | Go问答 · 接口排查 · encoding/json · JSON Go unmarshal encoding/json DisallowUnknownFields UnmarshalTypeError struct tag
- JSON 字段有值却解码为零值的排查清单
- 273浏览 收藏
-
- Golang · Go问答 | 40分钟前 | net/http · Go问答 · Go net/http http/2 ResponseController ResponseWriter Hijack
- ResponseWriter 在 HTTP/2 下为什么不能直接 Hijack
- 115浏览 收藏
-
- Golang · Go问答 | 40分钟前 |
- http.TimeoutHandler 超时后为何还会出现多次写入
- 368浏览 收藏
-
- Golang · Go问答 | 42分钟前 | 重定向 · net/http · HTTP客户端 · Go问答 · Go HTTP重定向 http.Client CheckRedirect 跨主机跳转
- Go http.Client CheckRedirect 处理跨域跳转的配置方法
- 445浏览 收藏
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 543次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 516次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 500次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 485次学习
-
- PubMedQA
- 深入了解PubMedQA生物医学问答数据集,涵盖其核心功能、使用方法及在临床决策、药物研发等场景的应用,助力提升NLP模型性能。
- 1010次使用
-
- H2O EvalGPT
- H2O EvalGPT是H2O.ai推出的开源LLM评估平台,提供详细的大模型性能排行榜、行业特定基准测试及A/B测试功能,助您快速选择最适合项目的高性能大语言模型。
- 1014次使用
-
- LMArena
- LMArena是加州大学伯克利分校推出的AI模型匿名评测平台。通过盲测投票机制,用户可对比不同大模型回答并生成实时排行榜,助力开发者优化模型及用户选择最佳AI工具。
- 1139次使用
-
- HELM
- 深入了解斯坦福推出的HELM(Holistic Evaluation of Language Models)大模型评测体系。本文解析其核心功能、安装配置步骤及应用场景,涵盖准确性、公平性、鲁棒性等多维度指标,助力开发者全面优化语言模型性能。
- 1108次使用
-
- MMBench
- MMBench是由上海人工智能实验室等机构联合推出的多模态基准测试平台,提供细粒度能力评估、大规模数据集及VLMEvalKit工具。本文详细介绍其核心功能、安装使用方法及应用场景,助力开发者全面评估多模态模型性能。
- 954次使用
-
- 用Nginx反向代理部署go写的网站。
- 2023-01-17 502浏览
-
- GoLand调式动态执行代码
- 2023-01-13 502浏览
-
- Go types.Selection.Type 与 Obj.Type 为什么不总是相同
- 2026-11-10 501浏览
-
- Go flag.FlagSet ContinueOnError 怎么捕获帮助输出和解析错误
- 2026-11-05 501浏览
-
- Go netip.ParseAddr 为什么拒绝带端口字符串
- 2026-11-03 501浏览

