使用.net maui创建普通Windows桌面应用程序?

um6iljoc  于 2022-11-18  发布在  Windows
关注(0)|答案(3)|浏览(480)

我计划创建一个跨平台的应用程序。最低限度的支持平台应该是android和windows。我想结束了一个经典的windows可执行文件,而不是一个UWP应用程序。新的maui平台看起来可能适合。
我已经下载了Visual Studio 2022的当前预发布版本并创建了一个新的maui项目。当我在windows上编译和运行它时,Visual Studio创建的应用程序是一个UWP应用程序。maui的官方微软页面声明:
可以为以下平台编写.NET多平台应用程序UI(.NET MAUI)应用程序:
Android 5.0(API 21)或更高版本。iOS 10或更高版本。macOS 10.13或更高版本,使用Mac Catalyst。Windows 11和Windows 10版本1809或更高版本,使用Windows UI库(WinUI)3。
https://learn.microsoft.com/en-us/dotnet/maui/supported-platforms
以下github上的问题看起来也可能创建widnows可执行文件:
发布到exe(非自包含)可以工作,但不要使用已发布的文件夹文件,而是使用构建构件,有关所有详细信息,请参阅下面的第3项
https://github.com/dotnet/maui/issues/4329
我对Windows支持的细节有点困惑。只有Windows才能创建UWP应用程序,还是我可以将其编译为普通的桌面应用程序?我可以将输出更改为普通的Windows可执行文件吗?如果可以,如何更改?

rkue9o1l

rkue9o1l1#

这是唯一对我有效的方法,但它有点麻烦。
打开终端并运行以下命令:

msbuild /restore /t:Publish /p:TargetFramework=net6.0-windows10.0.19041 /p:configuration=release /p:WindowsAppSDKSelfContained=true /p:Platform="any CPU" /p:PublishSingleFile=true /p:WindowsPackageType=None /p:RuntimeIdentifier=win10-x64

构建文件可以在以下位置找到:

jtw3ybtb

jtw3ybtb2#

.NET Maui应用程序不是UWP应用程序。它们是使用WinUI 3和生成Win32应用程序的Windows应用程序SDK构建的。有关Windows应用程序SDK的信息可以在here中找到,有关不同应用程序类型的信息可以在here中找到。
如果您询问是否可以发布Windows可执行文件(.exe),那么这是不可能的。.NET MAUI只允许发布MSIX包。

uhry853o

uhry853o3#

使用dotnet,则可能如下所示:
框架相关:

dotnet publish -f net6.0-windows -p:WindowsPackageType=None

独立式:

dotnet publish -f net6.0-windows -p:WindowsPackageType=None -p:SelfContained=true -p:WindowsAppSDKSelfContained=true

您的版本App.exe可以在\bin\Release\net6.0-windows中找到

相关问题