chore(packaging): default SlimHost module packaging

This commit is contained in:
meoacgx committed 2026-01-09 21:01:44 +08:00
1 parent 82566a3333
commit 0e94efab9f
2 files changed
+25 -2

No files matched your search

+2
View File
@@ -121,6 +121,8 @@ public void ConfigureServices(IServiceCollection services, ModuleHostContext con
powershell tools/package-module.ps1 -Project "src/YourModule/YourModule.csproj" -Manifest "src/YourModule/manifest.json"
```
> 默认会按宿主内置依赖做“轻量化打包”(等价于 `-SlimHost`)。如确需完整包可传 `-Full`(或 `-Slim:$false -SlimHost:$false`)。
产物默认输出到:`artifacts/modules/<moduleId>-<version>.tpm`
> 说明:该脚本依赖 Docker(会拉取/使用 `mcr.microsoft.com/dotnet/sdk:8.0` 镜像)。首次执行会比较慢属正常现象。
+23 -2
View File
@@ -16,11 +16,27 @@ param(
# 更激进的轻量打包:额外剔除宿主已内置的第三方依赖(EFCore/Sqlite/WTelegramClient 等)与多平台 native runtimes。
# 适用场景:目标宿主就是 TelegramPanel 主程序(必带这些依赖),并且部署环境固定(例如 Docker linux-x64)。
[Parameter(Mandatory = $false)]
[switch]$SlimHost
[switch]$SlimHost,
# 完整打包:不做任何剔除(体积更大,通常不推荐)。
# 说明:也可用 -Slim:$false -SlimHost:$false 达到同样效果。
[Parameter(Mandatory = $false)]
[switch]$Full
)
$ErrorActionPreference = "Stop"
if ($Full)
{
$Slim = $false
$SlimHost = $false
}
elseif (-not $PSBoundParameters.ContainsKey("Slim") -and -not $PSBoundParameters.ContainsKey("SlimHost"))
{
# 默认轻量化:未显式指定时,按宿主内置依赖(SlimHost)打包。
$SlimHost = $true
}
$repoRoot = (Resolve-Path ".").Path
$projectPath = Join-Path $repoRoot $Project
$manifestPath = Join-Path $repoRoot $Manifest
@@ -66,7 +82,12 @@ docker run --rm `
-w "/src" `
mcr.microsoft.com/dotnet/sdk:8.0 `
dotnet publish "$projectContainer" -c Release -o "$publishContainer" /p:UseAppHost=false
if ($LASTEXITCODE -ne 0) { throw "dotnet publish 失败(退出码:$LASTEXITCODE)" }
if ($LASTEXITCODE -ne 0)
{
Write-Warning "Docker publish 失败(退出码:$LASTEXITCODE),将回退到本机 dotnet publish(需本机已安装 dotnet)。"
dotnet publish "$projectPath" -c Release -o "$publishHost" /p:UseAppHost=false
if ($LASTEXITCODE -ne 0) { throw "dotnet publish 失败(退出码:$LASTEXITCODE)" }
}
$stagingLib = Join-Path $stagingHost "lib"
New-Item -ItemType Directory -Force -Path $stagingLib | Out-Null