How can I publish a .net MAUI Application to a Single executable? Is this even possible? I Have an application which I want my friends to use on their Windows PC. Is there any way without using the command prompt?
-
1if it's a UWP app, then you should be able to use the normal UWP publishing optionsJason– Jason2021-11-24 15:36:34 +00:00Commented Nov 24, 2021 at 15:36
-
1OR if its a "Windows Desktop" app, the answer is MSIX Packaging Tool. I haven't tried it yet - you might run into issues, given that both VS 2022 Preview and MAUI are .. Preview.ToolmakerSteve– ToolmakerSteve2021-12-15 03:00:21 +00:00Commented Dec 15, 2021 at 3:00
3 Answers
With the new release of .net MAUI 6.0.400 (Service Release 1) you can build your application to a working exe file.
In Visual Studio:
Right click your solution, open in terminal.
Run the following command:
msbuild /restore /t:build /p:TargetFramework=net6.0-windows10.0.19041 /p:configuration=release /p:WindowsAppSDKSelfContained=true /p:Platform=x64 /p:WindowsPackageType=None /p:RuntimeIdentifier=win10-x64
or if you want to target x86 for some legacy system:
msbuild /restore /t:build /p:TargetFramework=net6.0-windows10.0.19041 /p:configuration=release /p:WindowsAppSDKSelfContained=true /p:Platform=x86 /p:WindowsPackageType=None /p:RuntimeIdentifier=win10-x86
The build exe (x64) file can be found in \bin\x64\release\net6.0-windows10.0.19041\win10-x64
Publishing to a single file is possible but currently a little bugged, for example images need to be copied from the build folder into the publish folder to work. Images used via Blazor in the wwwroot folder work without a problem though.
Publishing command:
msbuild /restore /t:Publish /p:TargetFramework=net6.0-windows10.0.19041 /p:configuration=release /p:WindowsAppSDKSelfContained=true /p:Platform=x64 /p:PublishSingleFile=true /p:WindowsPackageType=None /p:RuntimeIdentifier=win10-x64
The build exe (x64) file can be found in \bin\x64\release\net6.0-windows10.0.19041\win10-x64\publish\
13 Comments
My MAUI project targeting .Net 7
1- Add a <WindowsPackageType> node to your .NET MAUI csproj file:
<WindowsPackageType Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">None</WindowsPackageType>
2- In your launchSettings.json set commandName to Project
3- Build your project in Release mode
4- Right click on the project -> Open Folder in File Explorer
5- The exe file located in: bin -> Release -> net7.0-windows10.0.19041.0 -> win10-x64
6 Comments
dotnet publish also works
