nathanAjacobs
nathanAjacobs

Reputation: 67

Is it possible to publish an unpackaged Windows App SDK (WinUI 3) as self contained single file?

I'm pretty sure I have all the right flags and everything set according to Microsoft Docs, however the UI dlls are not being included in the single file exe.

Upvotes: 3

Views: 2649

Answers (4)

Robert Evans
Robert Evans

Reputation: 11

AFAIK there is no way to produce a single EXE for net6.0 WinUI desktop app.

Fody does not work for this and while PublishSingleFile will indeed produce a single exe - it won't work, even with IncludeNativeLibrariesForSelfExtract. You will get DllNotFoundException exception at runtime. It is not resolved as of Windows App SDK 1.4.0.

This scenario is currently broken due to: https://github.com/microsoft/WindowsAppSDK/issues/2597

Evidently in single-file scenarios the single file host is in one directory and everything else is extracted into another directory.

Perhaps a custom build task to copy all references theoretically would work?

Upvotes: 1

Mike Francis
Mike Francis

Reputation: 71

Yes - with this (unpackaged / self-contained) command line:

dotnet publish -f net6.0-windows10.0.19041.0 -c Release -p:WindowsPackageType=None -p:SelfContained=true -p:WindowsAppSDKSelfContained=true

Note: This requires Windows App SDK 1.1.0 or above.

Upvotes: 0

Andrew KeepCoding
Andrew KeepCoding

Reputation: 13666

AFAIK, you can't. Self-Contained does not mean One-Single-File. It means that all the dependencies will be next to your EXE so you won't need to install runtimes to the target device.

Upvotes: 3

Bron Davies
Bron Davies

Reputation: 6004

Try using https://github.com/Fody/Costura/

It's great for legacy .NET projects. Newer frameworks have single-file executables as shown in their documentation

Upvotes: 0

Related Questions