WinUI AOT 发布
1,修改项目配置
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>App3</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x86;x64;ARM64</Platforms>
<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) >= 8">win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) < 8">win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
<UseWinUI>true</UseWinUI>
<EnableMsixTooling>true</EnableMsixTooling>
<!-- 添加以下内容 -->
<!--版本号最后一组需改为 .38 -->
<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>
<WindowsPackageType>None</WindowsPackageType>
<IsAotCompatible>true</IsAotCompatible>
<PublishAot>true</PublishAot>
<PlatformTarget>x64</PlatformTarget>
<CsWinRTAotOptimizerEnabled>true</CsWinRTAotOptimizerEnabled>
</PropertyGroup>
2,添加引用
Microsoft.Windows.CsWinRT
需要项目配置 WindowsPackageType = None
3,打包发布
打开项目所在位置执行以下命令
dotnet publish -r win-x64 -c Release
发布后如下
空项目最简运行如下路径这只能使用英文
最终最简运行成本5.52 MB
,
无运行库的环境会自动弹出运行库下载提示,根据提示下载安装即可.运行库体积59.3 MB