You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Action中dotnet build未生成带.exe后缀的WPF程序如何解决?

解决GitHub Action构建WPF应用无.exe扩展名的问题

你当前使用ubuntu-latest作为构建环境,Linux系统下dotnet构建Windows目标应用时,默认不会为可执行文件添加.exe扩展名。同时WPF是Windows专属UI框架,非Windows环境构建可能存在兼容性问题,以下是两种解决思路:

方案一:切换到Windows构建环境(推荐)

直接将构建作业的运行环境改为Windows,这样生成的文件会自动带有.exe扩展名,同时能保证WPF构建的完整性。修改后的Action配置如下:

name: .NET Build

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:
    # 更换为Windows环境
    runs-on: windows-latest

    steps:
    - name: Checking out repository
      uses: actions/checkout@v4
  
    - name: .NET setup
      uses: actions/setup-dotnet@v4
      with:
        dotnet-version: 9

    - name: Build
      run: dotnet build --configuration Release

    - name: Uploading artifacts
      uses: actions/upload-artifact@v4
      with:
        name: AxDa.XamlDocConverter Testing Tool
        path: TextConverterTest/bin/Release/net9.0-windows/
        overwrite: true
        if-no-files-found: error

方案二:在Linux环境下强制生成.exe扩展名(不推荐)

如果坚持使用Ubuntu环境,可通过以下两种方式处理:

方法1:修改构建命令

在dotnet build中添加参数,强制指定输出类型为Windows可执行文件:

- name: Build
  run: dotnet build --configuration Release -p:OutputType=WinExe

方法2:手动重命名文件

在上传产物前添加重命名步骤,给生成的可执行文件加上.exe扩展名:

- name: Rename executable to .exe
  run: mv TextConverterTest/bin/Release/net9.0-windows/TextConverterTest TextConverterTest/bin/Release/net9.0-windows/TextConverterTest.exe

内容的提问来源于stack exchange,提问作者AxD

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 00:58:16