I also had the problem. I believe, I could fix the problem by creating the WinUI3 project using the correct project template.
Before, I used the "Windows App SDK extension" in Visual Studio 2022. Then I removed this extension and instead installed the item "Windows APP SDK C# Templates" from the Visual Studio installer (item from "Installation details").
With the new / correct project template "Empty App, packaged (WinUI 3 in Desktop), I created a WinUI 3 project.
Here you find the relevant parts of the .cjproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>MyApp</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x86;x64;arm64</Platforms>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<PublishProfile>win10-$(Platform).pubxml</PublishProfile>
<UseWinUI>true</UseWinUI>
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.1.2" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.1" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>
</Project>
You can see, that two Nuget Packages are required:
Microsoft.WindowsAppSDK and Microsoft.Windows.SDK.BuildTools.
As you see, I used Windows App SDK 1.1.2 at that time. (I you publish an unpackaged app, the respective Window App SDK needs to be installed on the system, i can be found here)
In the project settings, take a look at the value in TargetFramework value. It seems that a value of simply "net6.0" does not work. In this post you will find this statement:
Changing net5.0-windows10.0.19041.0
to net6.0-windows10.0.19041.0
worked for me, too.