本文告訴大家,如何修復 GitHub Action 構建過程提示 error NETSDK1127: The targeting pack Microsoft.WindowsDesktop.App.WindowsForms is not installed. Please restore and try again. 錯誤
在進行 GitHub Action 構建時,如果自己的項目是一箇舊項目,採用舊的 .NET SDK 版本,將可以由於 GitHub Action 使用新的構建系統,缺乏舊的 SDK 導致構建失敗
失敗的錯誤信息輸出例子如下
error NETSDK1127: The targeting pack Microsoft.WindowsDesktop.App.WindowsForms is not installed. Please restore and try again. [D:\a\X\X\NewLife.Core\NewLife.Core.csproj::TargetFramework=net6.0-windows]
簡單的修復方法是給 GitHub 的 Action 的構建 yml 里加上 Setup dotNET
步驟,其 yml 添加的代碼如下
- name: Setup dotNET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
8.x
以上的 dotnet-version 請羅列出你所需的 SDK 版本,當然了,羅列太多的話,安裝時間也不短
以下是一份完全的構建 yml 文件的例子代碼
name: BuildAndTest
on: [push]
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: Setup dotNET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
8.x
- name: Build
run: dotnet build --configuration Release
- name: Test
run: dotnet test --configuration Release
具體的修復構建的 PR 請參閱 嘗試修復 CI 構建 by lindexi · Pull Request #135 · NewLifeX/X