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

GitHub CI/CD部署至Windows Server 2019时PowerShell启动应用闪退问题

问题:自托管Windows Server 2019上CI/CD部署后应用启动闪退

将代码部署到自托管Windows Server 2019机器时,所有步骤均正常执行,但最后一步通过PowerShell脚本启动应用时,应用仅短暂启动就闪退。手动在PowerShell中输入相同脚本、双击exe文件启动都能正常运行,仅CI/CD部署场景下出现该问题。

尝试过的脚本

脚本1

Start-Process -FilePath "C:\Users\Administrator\Desktop\Wialonfuelbackend\WialonCar.exe" -ArgumentList "C:\temp\TestProject1\TestProject1.pjs", "/run", "/exit", "/SilentMode"

脚本2

$procforstarting = @{
    FilePath = "C:\Users\Administrator\Desktop\Wialonfuelbackend\WialonCar.exe"
  }
  Start-Process @procforstarting

完整CI/CD YAML配置

name: Deploy .NET Core Console App

on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: self-hosted
    steps:
      - name: Output event data
        run: echo "{{ toJSON(github.event) }}"

      - name: Checkout code
        uses: actions/checkout@v2

      - name: Build and Publish
        run: |
          dotnet build --configuration Release
          dotnet publish --configuration Release --output ./publish

  CheckingServerFile:
    needs: build
    runs-on: self-hosted
    steps:
      - name: Stop Application If Running
        run: |
          $procforchecking = Get-Process -Name "WialonCar"
          if ($procforchecking -ne $null) {
            Stop-Process -InputObject $procforchecking -Force
          }
      - name: Check if Directory is Empty
        run: |
          $remotePath = "C:\Users\Administrator\Desktop\Wialonfuelbackend"  # Define $remotePath here
          $files = Get-ChildItem -Path $remotePath
          if ($files.Length -eq 0) {
            Write-Host "The directory is already empty. Continuing with deployment."
          } else {
            Write-Host "Removing old files..."
            Remove-Item -Force -Recurse -Path $remotePath\*
          }

  deploy:
    needs: CheckingServerFile
    runs-on: self-hosted
    steps:
      - name: Deploy Console App
        run: |
          $appPath = ".\publish"
          $remotePath = "C:\Users\Administrator\Desktop\Wialonfuelbackend"  # Define $remotePath here
          # Add error handling if needed
          xcopy /s /y $appPath\* $remotePath
  
  RunApplication:
    needs: deploy
    runs-on: self-hosted
    steps:
      - name: Run Console App
        if: success()
        run: |
          Start-Process -FilePath "C:\Users\Administrator\Desktop\Wialonfuelbackend\WialonCar.exe" -ArgumentList "C:\temp\TestProject1\TestProject1.pjs", "/run", "/exit", "/SilentMode"
      - name: Run Console App on Failure
        if: failure()
        run: Remove-Item -Force -Recurse -Path "C:\Users\Administrator\Desktop\Wialonfuelbackend\*"

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 21:40:01