WinUI3 發布 exe 檔案

筆者在建立專案時是選擇「空白應用程式,已封裝(桌面中的 WinUI 3)」

開啟專案的 .csproj 檔案,增加下面這行:
    
<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>WinExe</OutputType>
        <TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
        <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
        <RootNamespace>WinUi3AppSettingsTest</RootNamespace>
        <ApplicationManifest>app.manifest</ApplicationManifest>
        <Platforms>x86;x64;ARM64</Platforms>
        <RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
        <PublishProfile>win10-$(Platform).pubxml</PublishProfile>
        <UseWinUI>true</UseWinUI>
        <EnableMsixTooling>true</EnableMsixTooling>
        <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
        <UseRidGraph>true</UseRidGraph>
        
        <WindowsPackageType>None</WindowsPackageType>
    </PropertyGroup>
</Project>

    

發布的設定檔如下:
  • 組態: Release | x86
  • 部屬模式: 獨立式
  • 目標執行階段: win-x86
檔案大小約為 144MB

  • 組態: Release | x64
  • 部屬模式: 獨立式
  • 目標執行階段: win-x64
檔案大小約為 157MB

把整個資料夾複製到未安裝 .NET 8 的 Windows 11 電腦中,點選 .exe 檔案,可以正常執行,不需要開啟開發模式。

註: 在檔案發行選項中勾選「修剪未使用的程式碼」,x86 容量約為 65.4 MB ,x64 容量約為 74.7 MB
但是都無法正常開啟檔案

參考資料:

留言