Windows环境GitHub Actions打包仓库为Zip文件报错求助
在Windows环境GitHub Workflow中打包Zip文件的解决方案
你遇到的错误是因为Windows环境没有原生的zip命令,以下两种方案可以解决这个问题:
方案1:使用PowerShell原生命令Compress-Archive
Windows自带的PowerShell提供了Compress-Archive命令,可直接用于打包文件。将Workflow中的打包步骤替换为:
- name: Creating Zip shell: pwsh run: | Compress-Archive -Path (Get-ChildItem -Path . -Exclude .git,.github) -DestinationPath release.zip -Force
说明:
shell: pwsh指定使用PowerShell执行命令,确保兼容性Get-ChildItem -Exclude .git,.github排除不需要打包的目录-Force参数会覆盖已存在的release.zip文件(如果有)
方案2:使用预装的7zip工具
Windows环境的GitHub Runner默认预装了7zip,可通过7z命令完成打包,参数风格与Linux的zip更接近:
- name: Creating Zip run: 7z a release.zip . -xr!.git\* -xr!.github\*
说明:
7z a表示将文件添加到压缩包-xr!.git\*和-xr!.github\*用于排除指定目录及其子内容,Windows路径使用反斜杠分隔
完整修改后的Workflow示例(以PowerShell方案为例)
name: .NET on: push: branches: [ "main" ] pull_request: branches: [ "main" ] jobs: build: runs-on: [windows-latest] steps: - uses: actions/checkout@v3 - name: Set Up MS Build uses: microsoft/setup-msbuild@v1 - name: Restore dependencies run: nuget restore Solution.sln - name: Build Solution run: msbuild Solution.sln - name: Creating Zip shell: pwsh run: | Compress-Archive -Path (Get-ChildItem -Path . -Exclude .git,.github) -DestinationPath release.zip -Force
原错误信息:
The term 'zip' is not recognized as a name of a cmdlet, function, script file, or executable program
内容的提问来源于stack exchange,提问作者user19540656
相关产品推荐
相关产品推荐

