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中自动创建:
- 捕获注册表写入操作
- 在开发机上打开Process Monitor(ProcMon),设置过滤条件:进程名等于
TeeRegV3.exe,操作类型为RegSetValue。 - 运行
TeeRegV3.exe完成授权,捕获所有写入的注册表路径、键名和对应值。
- 在开发机上打开Process Monitor(ProcMon),设置过滤条件:进程名等于
- 在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中,避免明文泄露。
- 将捕获到的注册表操作整理为PowerShell脚本(示例):
方案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构建使用:
- 在开发机上生成许可证文件
- 正常构建项目,找到
obj\Release\<你的应用程序名>.exe.licenses文件。
- 正常构建项目,找到
- 将文件加入项目并配置构建
- 将该文件复制到项目的
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
相关产品推荐
相关产品推荐

