Publish a .NET MAUI app for Windows

Swetha vennapusa
Nerd For Tech
Published in
3 min readMay 26, 2024

We can distribute .Net MAUI App for windows in 2 ways

  • Packaged app
  • UnPackaged app

click here for features that requires package identifications.

Publish Packaged app:

We can publish app using visual studio or CLI . I suggest using CLI as we encountered some issues while publishing directly through visual studio.(at the time of writing this page)

Step 1:

Need to create new self signed certificate for publish

  1. Open power shell terminal and navigate to project directory
  2. Use the New-SelfSignedCertificate command given below to generate a self-signed certificate
New-SelfSignedCertificate -Type Custom -Subject "CN=<PublisherName>" -KeyUsage DigitalSignature -FriendlyName "My temp dev cert" -CertStoreLocation "Cert:\CurrentUser\My" -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}")

<PublisherName> replace it with your publisher name.

FriendlyName you can use any string you want.

after executing this command thumbprint will be generated, copy it for further use

  1. It is an optional step if you want to check whether your certificate created or incase you forgot to save your thumbprint.
Get-ChildItem "Cert:\CurrentUser\My" | Format-Table Thumbprint, Subject, FriendlyName

this command gives all existing certificate thumbprints, subject and Friendly name.

If you want to export certificate from your device:

use Export-PfxCertificate command as below

$password = ConvertTo-SecureString -String <Password> -Force -AsPlainText  Export-PfxCertificate -cert "Cert:\CurrentUser\My\<ThumbPrint>" -FilePath <Your Specifiedpath>.<ThumbPrint>.pfx -Password $password

Replace <Password>, <ThumbPrint>,<Your Specifiedpath>

Step2:

Add following code in your .csroj file

<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows' and '$(Configuration)' == 'Release'">
<AppxPackageSigningEnabled>true</AppxPackageSigningEnabled>
<PackageCertificateThumbprint>Enter Your Thumprint Generated</PackageCertificateThumbprint>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows' and '$(RuntimeIdentifierOverride)' != ''">
<RuntimeIdentifier>$(RuntimeIdentifierOverride)</RuntimeIdentifier>
</PropertyGroup>

Replace with your thumbprint generated while creating self signed certificate in PackageCertificateThumbprint

Step 3:

Now open your Developer Command Prompt for VS 2022 terminal and execute below command.

dotnet publish <ProjectName> -f net8.0-windows10.0.19041.0 -c Release -p:RuntimeIdentifierOverride=win10-x64 --self-contained

Replace ProjectName with your csroj file name ex: (if you have Sample.csroj replace <ProjectName> with Sample.

--self-contained don't miss to add this line at the end as from .Net8 we need to specify explicitly otherwise package will not contain .Net runtime SDK and will ask user to download.

Publishing builds and packages the app, copying the signed package to the bin\Release\net8.0-windows10.0.19041.0\win10-x64\AppPackages\<appname>\ folder.

<appname> is a folder named after both your project and version. In this folder, there’s an msix file, and that’s the app package.

Publish UnPackaged app:

Step1:

Add below code in your .csroj project

<WindowsPackageType>None</WindowsPackageType>

and make sure your launchSettings.json looks as below

{
"profiles": {
"Windows Machine": {
"commandName": "Project",
"nativeDebugging": false
}
}
}

Step2:

Run below command in your Developer Command Prompt for VS 2022 terminal

dotnet publish <Project Name>-f net8.0-windows10.0.19041.0 -c Release -p:RuntimeIdentifierOverride=win10-x64 -p:WindowsPackageType=None --self-contained

Publishing builds the app, copying the executable to the bin\Release\net8.0-windows10.0.19041.0\win10-x64\publish folder. In this folder, there’s an exe file, and that’s the built app.

--self-contained don't miss to add this line at the end for unpackaged apps we need to specify explicitly otherwise package will not contain required windows SDK runtime

also make sure your MAUI package version is above 8.0.7 as we encountered some issues in lower versions while trying to publish signed app .

Please support me here

Image of author using buy me a coffee logo

--

--