GitHub快速開始
指南

構建與釋出

用 nsgo check 驗證全部目標平臺,在 nsgo.yaml 中配置應用後設資料、圖示和簽名,並用 nsgo build 為 macOS、Windows、Linux、Web、iOS 和 Android 構建釋出包。

配置 nsgo.yaml

nsgo build 從專案根目錄的 nsgo.yaml 讀取應用標識、圖示、簽名和預設構建目標。命令列上的引數(-name、-id、-version、-build-number、-output、-target、-channel)會覆蓋本次構建對應的 nsgo.yaml 欄位。

name: My Game
id: com.example.mygame
version: 1.0.0
build_number: 1
copyright: "© 2026 Example Studio"

icon:
  apple: assets/AppIcon.icon   # Icon Composer .icon(macOS/iOS)或 .icns(僅 macOS)
  png: assets/Icon.png         # 正方形 PNG(推薦 1024x1024)

build:
  output: dist
  installers: true
  targets:
    - macos_arm64
    - macos_x64
    - windows_x64
    - windows_arm64
    - linux_x64
    - linux_arm64
    - web
    - ios
    - android_arm64
  • id:反向域名格式的 Bundle ID / Application ID(例如 com.example.mygame)。各版本間請保持不變,Apple App Store、Google Play 和 Microsoft Store 都以此識別你的應用。
  • version:面向使用者的語義化版本號(Apple 的 CFBundleShortVersionString、Android 的 versionName)。
  • build_number:每次提交商店都必須遞增的整數構建號(Apple 的 CFBundleVersion、Android 的 versionCode)。省略時會從 version 推導。
  • resources/ 與 assets/:執行時載入的遊戲資源("asset:...")放在 resources/ 中,會原樣打入每個安裝包;圖示等構建期輸入放在 assets/ 中,由工具轉換成各平臺圖示格式。可以在 nsgo.yaml 裡用 mobile.exclude_resources 從 iOS 和 Android 包中排除僅桌面端使用的資源。

應用圖示

把預設圖示放到 assets/ 目錄下,nsgo build 無需額外配置即可自動識別:

  • assets/AppIcon.icon(Apple Icon Composer 格式)或 assets/AppIcon.icns(僅 macOS),用於 macOS 和 iOS。
  • assets/Icon.png(正方形 PNG,建議 1024×1024),用於 Windows、Linux、Android、Web,以及未配置 icon.apple 的 Apple 目標。

如果需要區分開發版和正式版圖示,可以放置帶 -dev 字尾的檔案(assets/AppIcon-dev.icon、assets/Icon-dev.png)或在 dev.icon 中指定,nsgo dev 會自動使用它們。

對於桌面端安裝程式,還可以在 nsgo.yaml 中設定 macos.dmg_icon、macos.dmg_background(PNG,可選同名 @2x 圖)、windows.installer_icon 和 windows.uninstaller_icon。

構建前檢查所有目標平臺

先檢查本機已安裝的工具鏈:

go tool nsgo doctor

在構建釋出包前,用 nsgo check 對所有目標平臺執行 go vet(以及目錄檢查):

go tool nsgo check -target all

或者顯式檢查全部 6 個遊戲平臺:

go tool nsgo check -target macos,windows,linux,web,ios,android
  • 傳入 -jobs N 可並行檢查最多 N 個目標。
  • 僅寫作業系統名(macos、windows、linux)會自動展開為 arm64 和 x64 兩個架構;android 展開為 android_arm64(android_x64 需要 Android NDK)。
  • 在 Linux 或 Windows 主機上,-target all 會跳過需要 macOS 與 Xcode 的 Apple 目標;如果顯式指定 ios 而缺少 Xcode,則會報錯。

無頭測試執行 go tool nsgo test;在真實平臺上執行測試則使用 go tool nsgo test -target macos|windows|linux|web|ios_simulator|android。

構建釋出包

nsgo build 會構建剝離除錯符號的正式版二進位制,在 <output>/<name>-<version>-<target> 下為每個目標生成目錄,並輸出可分發的釋出檔案。

# 按 nsgo.yaml 中配置的目標構建
go tool nsgo build

# 構建當前機器上 Go 與 Xcode 支援的全部目標
go tool nsgo build -target all

# 構建商店提交格式的包,而非直接下載的安裝器
go tool nsgo build -channel store -target macos,windows,linux,ios,android

-channel 控制打包格式與更新通道:

  • direct(預設):直接分發安裝器與壓縮包(.dmg、NSIS .exe、.deb/Arch/.AppImage、.apk、.ipa、Web .zip)。
  • store:應用商店提交包(Mac App Store .pkg、Microsoft Store .msix、Flathub .tar.gz + Flatpak 清單、Google Play .aab、iOS .ipa)。
  • none:跳過自動更新源配置,保留直接分發格式。

如果桌面端只需要未打包的應用目錄,傳入 -installers=false。傳入 -run 可在構建完成後立刻在本機、連線的裝置或本地 Web 伺服器上執行產物。

為資源署名

資源採用的多數許可證(包括知識共享署名許可和 SIL 開放字型許可證)都要求隨遊戲附上作者和許可證。把它們記錄在每個資源旁邊匯入設定附屬檔案(hero.png.import.yaml)的 credit 部分;為每個平臺執行 nsgo build 的 nsgo game release 隨後會在各個包旁邊寫出 CREDITS.md,供商店頁面或下載頁面使用,並且只要 game.yaml 的 assets 部分裡有資源缺少署名就拒絕構建。nsgo game credits 不構建,只檢查署名並列印該檔案;在釋出之前執行 nsgo game credits -out resources/CREDITS.md 還能讓每個包內都帶上它,因為 nsgo build 會把 resources 資料夾複製進每個包(見命令列)。遊戲從 assets 部分之外載入的資源不會被列出,需要自行署名。

各目標平臺說明

平臺 目標名 直接分發(-channel direct) 商店釋出(-channel store) 構建主機要求
macOS macos_arm64、macos_x64(macos) .app + .dmg 沙盒 .pkg 簽名與公證需 macOS
Windows windows_x64、windows_arm64(windows) .exe 目錄 + NSIS 安裝程式 .msix 任意平臺(Go 交叉編譯)
Linux linux_x64、linux_arm64(linux) 二進位制目錄 + .deb、Arch 包、.AppImage .tar.gz + AppStream + Flatpak 清單 任意平臺(Go 交叉編譯)
Web web 靜態 WebAssembly 站點 + .zip 同靜態站點 任意平臺
iOS ios、ios_simulator .ipa .ipa macOS + Xcode
Android android_arm64(android)、android_x64 .apk .aab 任意平臺(android_x64 需 NDK)

遊戲主機(Nintendo Switch、PlayStation 和 Xbox)不是目標平臺:它們的 SDK 受保密協議(NDA)約束,且需要 C 工具鏈,而 NSGo 只用 Go。

macOS

構建 Apple Silicon、Intel 或同時構建兩者:

go tool nsgo build -target macos
  • 程式碼簽名:未設定簽名身份時使用臨時簽名(ad hoc,僅適合本機測試,下載後會被 Gatekeeper 攔截)。直接分發請通過 sign.identity 或 -sign 指定 Developer ID Application 證書:
    go tool nsgo build -target macos -sign "Developer ID Application: Example Studio (TEAMID)"
  • 公證(Notarization):為了讓其他 Mac 無警告開啟,請在 sign.notarize 或 -notarize <profile> 指定通過 xcrun notarytool store-credentials 儲存的鑰匙串配置。在 CI 環境中,可改為設定 App Store Connect API 金鑰環境變數:NSGO_NOTARY_KEY(.p8 路徑)、NSGO_NOTARY_KEY_ID 和 NSGO_NOTARY_ISSUER。nsgo build 會自動提交 .dmg(或打包的 .app)、等待稽核並將票據裝訂(staple)到 .app 和 .dmg 上。
  • Mac App Store:設定 macos.category(例如 public.app-category.games)、sign.macos_profile(Mac App Store 描述檔案)以及可選的 sign.installer(Mac Installer Distribution 證書),然後以 -channel store 構建:
    go tool nsgo build -channel store -target macos
    nsgo build 會啟用 App Sandbox 簽名並生成可直接通過 Transporter 上傳的 .pkg 安裝包。

Windows

構建 x64、ARM64 或兩者:

go tool nsgo build -target windows
  • 直接分發:生成應用目錄和 NSIS 安裝程式(預設 -installers=true)。在 nsgo.yaml 中填寫 windows.publisher 和 copyright,用於填充執行檔後設資料和解除安裝項資訊。
  • 程式碼簽名:為執行檔和安裝程式簽名以避免 SmartScreen 攔截警告。通過 -certificate(或 sign.certificate)指定 PKCS#12 .pfx 證書,用環境變數 NSGO_CERTIFICATE_PASSWORD 提供密碼,並可設定 RFC 3161 時間戳伺服器(-timestamp-url / sign.timestamp_url,預設為 http://timestamp.digicert.com):
    NSGO_CERTIFICATE_PASSWORD="$PFX_PASSWORD" \
      go tool nsgo build -target windows -certificate certs/win.pfx
    如果證書在硬體令牌或雲簽名服務中,請使用 -sign-command(或 sign.sign_command),其中 %1 代表待簽名檔案路徑。
  • Microsoft Store:在 nsgo.yaml 中填寫 Partner Center 分配的 windows.store.identity、windows.store.publisher(CN=...)和 windows.store.publisher_name,再執行 -channel store 生成 .msix 包(包本身不簽名,由商店釋出時簽名):
    go tool nsgo build -channel store -target windows

Linux

構建 x64、ARM64 或兩者:

go tool nsgo build -target linux
  • 直接分發:生成 .deb(Debian/Ubuntu)、Arch 軟體包和 .AppImage。在 nsgo.yaml 中配置桌面後設資料:
    linux:
      categories: [Game]
      maintainer: "Example Studio <games@example.com>"
      summary: "A 2D adventure game"
      license: MIT
    若遊戲附帶了外部輔助程式,可通過 linux.depends 和 linux.recommends 宣告額外依賴。
  • Flathub / Flatpak:使用 -channel store 會生成包含 <id>.metainfo.xml AppStream 後設資料的 .tar.gz 歸檔,以及面向 GNOME 執行時的 flatpak/<id>.yml 清單(可用 linux.flatpak_runtime 覆蓋預設執行時版本)。可將清單提交到 Flathub,或本地用 flatpak-builder 構建。

Web

構建靜態 WebAssembly 釋出包:

go tool nsgo build -target web

部署前可直接在本地啟動靜態服務驗證正式構建:

go tool nsgo build -target web -run

dist/<name>-<version>-web/ 中包含 HTML、JS、WebAssembly 二進位制和 resources/ 檔案,同時 releases 目錄會生成一份 .zip 壓縮包。將目錄內容上傳到任意靜態託管服務(GitHub Pages、Cloudflare Pages、Netlify、itch.io 或 S3)即可上線。注意瀏覽器要求在首次使用者手勢之後才能播放音訊(詳見 sound)。

iOS

需要在安裝了 Xcode 的 macOS 上構建。可構建真機 .ipa 或模擬器包:

go tool nsgo build -target ios
go tool nsgo build -target ios_simulator
  • 簽名:通過 sign.profile(或 -profile)提供與 id 匹配的 App Store、Ad Hoc 或 Development 描述檔案。nsgo build 會自動從鑰匙串選擇匹配的簽名證書,也可以用 sign.identity(或 -sign)顯式指定。
  • 商店提交注意事項:
    • 使用 Apple 的 Transporter 應用或 Xcode 將 <name>.ipa 上傳至 App Store Connect / TestFlight。
    • 每次上傳都必須遞增 build_number(CFBundleVersion)。
    • 使用 apple.requires_full_screen 和 apple.orientations(portrait、portrait_upside_down、landscape_left、landscape_right)配置 iPad 分屏與螢幕方向,並在 apple.info 下新增所需的 Info.plist 欄位。apple.orientations 宣告全屏 iPad 允許的方向,而遊戲在執行時通過 cx.RequestOrientation 發出的請求在 iPhone 和 iPad 上都會生效(見手機上的螢幕方向)。在 iPad 上,UIKit 只允許兩者共有的方向,因此要列出遊戲請求的每個方向,例如橫屏遊戲列出 landscape_left 和 landscape_right;請求與 apple.orientations 沒有共同方向時,iPad 將沒有可用的方向。

Android

構建 ARM64(只需要 Go,使用 CGO_ENABLED=0,無需 Android SDK 或 NDK):

go tool nsgo build -target android_arm64

如需同時構建 android_x64(用於 x86_64 模擬器或 Chromebook),請安裝 Android NDK 後傳入 -target android_arm64,android_x64。

  • 簽名:通過 sign.keystore(或 -keystore)指定 PKCS#12 或 JKS 金鑰庫,通過 sign.key_alias(或 -key-alias)指定金鑰別名。切勿把密碼寫入 nsgo.yaml,請使用環境變數傳遞:
    NSGO_KEYSTORE_PASSWORD="$STORE_PW" NSGO_KEY_PASSWORD="$KEY_PW" \
      go tool nsgo build -channel store -target android_arm64 \
      -keystore certs/upload.p12 -key-alias upload
    未配置金鑰庫時,nsgo build 會使用專案自帶的除錯金鑰簽名 APK(僅限側載測試,無法上傳 Google Play)。
  • Google Play:使用 -channel store 生成已簽名的 .aab(Android App Bundle)上傳至 Google Play Console。每次上傳需遞增 build_number(versionCode),按 Google Play 當前要求設定 android.target_sdk(minSdkVersion 為 28),並在 android.permissions 下宣告額外許可權。
  • 螢幕方向:清單不固定螢幕方向;遊戲在執行時通過 cx.RequestOrientation 請求遊玩時的方向(見手機上的螢幕方向)。
編輯此頁