7

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

  • When I use the JetBrains rider to publish single .exe file, it just doesn't start.

  • While, packaged application published using visual studios, doesn't start the application by clicking on .exe file but by only through visual studio.

  • And in unpackaged publish, .exe file (still not single file) do runs, but most of my assets doesn't load and throws error while executing this line of code

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

Some requirements I have:

  • After publishing, a single .exe file is generated, that I can share or upload somewhere, without any other dependencies.
  • My application uses task scheduler to run itself through Environment.ProcessPath in another instance. So, it'll be necessary that the app runs through .exe file.
  • Sending notification is optional, and I am willing to publish my app without that.

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

1 Answer 1

8

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>
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for this. Everything seems to be working fine other than notifications. Is there any way to solve that issue. Also, how an installer is created? If you have any video or resource, please link me up.
@chiraggoyal - Since you mention it, PowerToys is open source github.com/microsoft/PowerToys, you can have a look at how it's done in github.com/microsoft/PowerToys/tree/main/installer/…
You need to do a few changes when using AppNotifications on a non-packaged app.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.