build: AOT 发布后自动 UPX nrv9 压缩(40MB→14MB)
- build.bat:publish 后清理产物 + upx -9 自动压缩,支持 SKIP_UPX 跳过、缺 upx 仅警告 - csproj:新增框架依赖单文件发布路径(非 AOT 时),.Static 包改为仅 AOT 引用
This commit is contained in:
+20
-2
@@ -16,7 +16,16 @@
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- NativeAOT 发布配置(仅 publish 生效):单文件原生 exe -->
|
||||
<!-- 框架依赖单文件发布(默认,仅 publish 生效):需目标机装 .NET 10 运行时
|
||||
原生库(Skia/HarfBuzz/ANGLE)随单文件打包、运行时自解压 -->
|
||||
<PropertyGroup Condition="'$(PublishAot)' != 'true'">
|
||||
<PublishSingleFile>true</PublishSingleFile>
|
||||
<SelfContained>false</SelfContained>
|
||||
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
|
||||
<DebuggerSupport>false</DebuggerSupport>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- NativeAOT 发布配置(需 -p:PublishAot=true,仅 publish 生效):单文件原生 exe -->
|
||||
<PropertyGroup Condition="'$(PublishAot)' == 'true'">
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<StripSymbols>true</StripSymbols>
|
||||
@@ -50,8 +59,9 @@
|
||||
CoreUtils.SkiaSharp.Static 含 skia + libHarfBuzzSharp 的 .lib,CoreUtils.ANGLE.Static 含 ANGLE
|
||||
两包各自的 .targets 会在 PublishAot 时自动追加 NativeLibrary,这里只补 DirectPInvoke 与系统 lib
|
||||
版本对应:Avalonia 12 → SkiaSharp 3.119
|
||||
仅 AOT 需要;框架依赖单文件用 Avalonia 自带的动态 Skia 原生库
|
||||
-->
|
||||
<ItemGroup>
|
||||
<ItemGroup Condition="'$(PublishAot)' == 'true'">
|
||||
<PackageReference Include="CoreUtils.SkiaSharp.Static" Version="3.119.0.1" />
|
||||
<PackageReference Include="CoreUtils.ANGLE.Static" Version="7151.0.1" />
|
||||
</ItemGroup>
|
||||
@@ -79,4 +89,12 @@
|
||||
<Delete Files="@(_AotJunk)" />
|
||||
</Target>
|
||||
|
||||
<!-- 框架依赖单文件清理:原生库符号(libSkiaSharp.pdb 等)与托管 .pdb 发布不需要,只留 notify.exe -->
|
||||
<Target Name="CleanSingleFileOutput" AfterTargets="Publish" Condition="'$(PublishAot)' != 'true' And '$(PublishSingleFile)' == 'true'">
|
||||
<ItemGroup>
|
||||
<_SingleFileJunk Include="$(PublishDir)*.pdb" />
|
||||
</ItemGroup>
|
||||
<Delete Files="@(_SingleFileJunk)" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
||||
+18
-3
@@ -9,7 +9,7 @@ if exist "%VSWHERE%" (
|
||||
for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do set "VSPATH=%%i"
|
||||
)
|
||||
if defined VSPATH if exist "%VSPATH%\VC\Auxiliary\Build\vcvars64.bat" (
|
||||
echo === 配置 MSVC 环境: %VSPATH% ===
|
||||
echo === Configure MSVC env: %VSPATH% ===
|
||||
call "%VSPATH%\VC\Auxiliary\Build\vcvars64.bat" >nul
|
||||
)
|
||||
|
||||
@@ -17,10 +17,25 @@ echo === NativeAOT publish (win-x64) -^> bin\notify.exe ===
|
||||
dotnet publish Notify -c Release -r win-x64 -p:PublishAot=true -o bin
|
||||
if errorlevel 1 (
|
||||
echo.
|
||||
echo *** 发布失败。若提示找不到 link.exe,请从 "Developer Command Prompt for VS" 运行本脚本 ***
|
||||
echo *** publish failed. If link.exe not found, run from "Developer Command Prompt for VS" ***
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
rem 清理发布目录残留:只留 notify.exe(AOT 下 -o 拷贝时序使 csproj 内清理不可靠,这里统一处理)
|
||||
del /q bin\*.pdb bin\*.dll bin\*.lib >nul 2>&1
|
||||
|
||||
rem 自动 UPX 压缩(NRV -9:大小/解压速度最佳平衡,约 40MB->14MB,启动仅多 ~100ms)
|
||||
rem 跳过压缩:先 set SKIP_UPX=1 再运行本脚本
|
||||
if "%SKIP_UPX%"=="1" goto after_upx
|
||||
where upx >nul 2>&1
|
||||
if errorlevel 1 goto no_upx
|
||||
echo === UPX compress (nrv9) ===
|
||||
upx -9 bin\notify.exe
|
||||
goto after_upx
|
||||
:no_upx
|
||||
echo *** WARNING: upx not found on PATH, skip compression (output is uncompressed exe) ***
|
||||
:after_upx
|
||||
|
||||
echo.
|
||||
echo === 完成: %CD%\bin\notify.exe ===
|
||||
echo === Done: %CD%\bin\notify.exe ===
|
||||
endlocal
|
||||
|
||||
Reference in New Issue
Block a user