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

GitHub Actions CI/CD构建含TeeChart .NET的WinForms应用遇授权问题

解决GitHub Actions构建TeeChart .NET v3时的许可证错误问题

核心问题

在GitHub Actions的Windows runner上构建包含TeeChart .NET v3的项目时,因缺少TeeRegV3.exe生成的开发许可证注册表项,触发以下编译错误:

Resources\licenses.licx(1): error LC0004: Exception occurred creating type 'Steema.TeeChart.TChart, TeeChart, Version=3.5.3498.27368, Culture=neutral, PublicKeyToken=9c8126276c77bdb7' System.ComponentModel.LicenseException: An instance of type 'Steema.TeeChart.Chart' was being created, and a valid license could not be granted for the type 'Steema.TeeChart.Chart'.

由于无法在runner上运行GUI授权工具,且不想使用自托管runner,以下是几种可行的自动化解决方案:


方案1:捕获并复刻开发机的注册表项

TeeRegV3.exe本质是向系统写入特定注册表项来授权开发环境,可通过工具捕获这些项后,在runner中自动创建:

  1. 捕获注册表写入操作
    • 在开发机上打开Process Monitor(ProcMon),设置过滤条件:进程名等于TeeRegV3.exe,操作类型为RegSetValue。
    • 运行TeeRegV3.exe完成授权,捕获所有写入的注册表路径、键名和对应值。
  2. 在GitHub Actions中自动写入注册表
    • 将捕获到的注册表操作整理为PowerShell脚本(示例):
      # 创建TeeChart注册表根路径(如果不存在)
      New-Item -Path "HKLM:\Software\Steema Software\TeeChart for .NET v3" -Force | Out-Null
      # 写入许可证相关键值(替换为你捕获到的实际内容)
      New-ItemProperty -Path "HKLM:\Software\Steema Software\TeeChart for .NET v3" -Name "LicenseKey" -Value "你的许可证密钥" -PropertyType String -Force
      New-ItemProperty -Path "HKLM:\Software\Steema Software\TeeChart for .NET v3" -Name "LicenseName" -Value "你的许可证名称" -PropertyType String -Force
      
    • 在Workflow的Build solution步骤前添加执行脚本的步骤:
      - name: Setup TeeChart license registry
        shell: powershell
        run: |
          New-Item -Path "HKLM:\Software\Steema Software\TeeChart for .NET v3" -Force | Out-Null
          New-ItemProperty -Path "HKLM:\Software\Steema Software\TeeChart for .NET v3" -Name "LicenseKey" -Value "${{ secrets.TEECHART_LICENSE_KEY }}" -PropertyType String -Force
          New-ItemProperty -Path "HKLM:\Software\Steema Software\TeeChart for .NET v3" -Name "LicenseName" -Value "${{ secrets.TEECHART_LICENSE_NAME }}" -PropertyType String -Force
      
    • 注意:将许可证密钥和名称存入GitHub仓库的Secrets中,避免明文泄露。

方案2:跳过编译时的许可证检查

若运行时许可证已嵌入发布的EXE,可通过修改MSBuild参数禁用编译阶段的许可证验证:

  • 在Workflow的Build solution步骤中添加/p:GenerateLicensesFile=false参数,跳过licenses.licx文件的处理:
    - name: Build solution
      run: msbuild "<App name>\<App name>.wixproj" /p:Configuration="Release" /p:Platform="x64" /p:TargetFrameworkVersion="v4.7.2" /p:RestorePackages=true /p:GenerateLicensesFile=false
    
  • 若上述参数无效,可尝试修改项目的.csproj文件(对应实际应用项目,而非wixproj),添加以下配置:
    <PropertyGroup>
      <GenerateLicensesFile>false</GenerateLicensesFile>
      <SkipLicenseValidation>true</SkipLicenseValidation>
    </PropertyGroup>
    

方案3:预生成许可证文件并加入版本控制

在开发机上预生成.licenses文件,直接提供给CI构建使用:

  1. 在开发机上生成许可证文件
    • 正常构建项目,找到obj\Release\<你的应用程序名>.exe.licenses文件。
  2. 将文件加入项目并配置构建
    • 将该文件复制到项目的Resources目录,提交到版本控制。
    • 修改应用项目的.csproj文件,指定预生成的许可证文件路径:
      <PropertyGroup>
        <LicenseFile>Resources\<你的应用程序名>.exe.licenses</LicenseFile>
      </PropertyGroup>
      
    • 或在Workflow的构建步骤中添加参数:
      - name: Build solution
        run: msbuild "<App name>\<App name>.wixproj" /p:Configuration="Release" /p:Platform="x64" /p:TargetFrameworkVersion="v4.7.2" /p:RestorePackages=true /p:LicenseFile="Resources\<你的应用程序名>.exe.licenses"
      

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 03:18:37