20

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?

2
  • 1
    if it's a UWP app, then you should be able to use the normal UWP publishing options Commented Nov 24, 2021 at 15:36
  • 1
    OR 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. Commented Dec 15, 2021 at 3:00

3 Answers 3

25

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\

Sign up to request clarification or add additional context in comments.

13 Comments

Did what you said and got error :sigh. C:\Users\Gordon\source\repos\RouteIt\RouteIt.sln.metaproj : error MSB4126: The specified solution configuration "release|x64" is invalid. Please specify a valid solution configuration using the Configuration and Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuratio n=Debug /p:Platform="Any CPU") or leave those properties blank to use the default solution configuration. [C:\Users\Gordon\source\repos\Rout eIt\RouteIt.sln] Why is release x64 invalid, it is an 64 bit m/c
I've looked at the error and tried things, but no joy. I have set the drop down to release and built the solution from Build, build and I have a folder with hundreds of files and a RouteIt.exe but that doesn't do anything, even in situ.
So sorry :( C:\Program Files\dotnet\sdk\6.0.400-preview.22330.6\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolu tion.targets(267,5): error NETSDK1005: Assets file 'C:\Users\Gordon\source\repos\RouteIt\obj\project.assets.json' do esn't have a target for 'net6.0-windows10.0.19041'. Ensure that restore has run and that you have included 'net6.0-w indows10.0.19041' in the TargetFrameworks for your project. [C:\Users\Gordon\source\repos\RouteIt\RouteIt.csproj]
Ingo's first solution to build a working executable (in a folder with all the junk) seems to work, though for my app using mapsui I don't get the map to appear at first as I do when I run from Visual Studio. After that it is fine(ish) But I have not yet got a solution for a standalone exe. I raised this issue in the .net Maui Github, but as per usual they don't seem very interested. I've still not bothered to wrap it up in the installer as I have a (faint) hope that as more people use Maui the clamour for resolution might prompt them to take action.
@gfmoore I don't get why this isn't a priority. Regardless of whatever hip installation process is the flavor of the day, running any .exe file as an end user should be possible with all the security implications that entails, and has always entailed. How is Microsoft expecting developers to migrate from WinForms and the like without basic functionality like this? You'd have thought from Windows 8 and the Microsoft Store failure that they've realized by now that users enjoy freedom, and not being forced into a shoehorned box without options.
|
13

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>

enter image description here

2- In your launchSettings.json set commandName to Project

enter image description here

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

After adding this dotnet publish also works
The commands in the accepted answer also work well in this config (using dotnet 6.0)
Tried that approach with the latest .NET8.0. That did not work.
I tried on my .net8.0 maui project and it worked. I have to manage a little problem with my icons but it looks ok
This worked for me with .NET 8.0.1 (2024-10-08). I edited the two files with an editor before loading the project in Visual Studio 2022. Then I switched from Debug to Release and ran the Build Solution command in VS.
|
1

Try this for net8.0-windows10.0.19041.0

msbuild /restore /t:build /p:TargetFramework=net8.0-windows10.0.19041.0 /p:configuration=release /p:WindowsAppSDKSelfContained=true /p:Platform=x64 /p:WindowsPackageType=None /p:RuntimeIdentifier=win-x64

Comments

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.