chirag goyal
chirag goyal

Reputation: 133

Right way to publish WinUI3 app in single .exe file

I have created a project in winui3, however, I just can't find a way to publish the application into a single .exe file.

AppNotificationManager.Default.Show(new AppNotificationBuilder().AddText("Text").BuildNotification());

Some requirements I have:

Other than this, I have seen the Microsoft's PowerToys application, and I am pretty sure that too is made in winui3, and they somehow managed to provide a single .exe on their github page.

If anyone can please help me with this, I'll be very grateful.

TLDR: How to generate single .exe file in winui3 which runs

Upvotes: 6

Views: 6166

Answers (1)

Andrew KeepCoding
Andrew KeepCoding

Reputation: 13331

First of all, at this moment at least, you can't create a single file EXE for WinUI 3. PowerToys is not an exception and I guess you are talking about its installer.

What you can do is these 2 configurations. The videos are from my channel, if you are interested in.

  • Make your app non-packaged (unpackaged) and self-contained. (video)

  • Reduce unnecessary folders in the output folder. (video)

TLDR: Your *.csproj should have these lines:

<Project ...>
  <PropertyGroup>

    ...

    <WindowsPackageType>None</WindowsPackageType>
    <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
  </PropertyGroup>

  ...

  <Target Name="RemoveFoldersWithMuiFiles" AfterTargets="Build">
    <ItemGroup>
      <RemovingFiles Include="$(OutDir)*\*.mui" Exclude="$(OutDir)en-us\*.mui" />
      <RemovingFolders Include="@(RemovingFiles->'%(RootDir)%(Directory)')" />
    </ItemGroup>
    <RemoveDir Directories="@(RemovingFolders)" />
  </Target>
</Project>

Upvotes: 7

Related Questions