将 .net MAUI 应用程序发布为 Windows 可执行文件

问题描述 投票:0回答:2

如何将 .net MAUI 应用程序发布到单个可执行文件?这可能吗? 我有一个应用程序,我想让我的朋友在他们的 Windows PC 上使用。有没有不使用命令提示符的方法?

c# .net visual-studio publish maui
2个回答
16
投票

随着 .net MAUI 6.0.400(服务版本 1)的新版本,您可以将您的应用程序构建为一个工作的 exe 文件。

在视觉工作室中: 右键单击您的解决方案,在终端中打开。 运行以下命令:

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

或者如果你想为某些遗留系统定位 x86:

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

build exe (x64) 文件可以在 in\x64 中找到 释放 et6.0-windows10.0.19041\win10-x64


可以发布到单个文件,但目前存在一些问题,例如需要将图像从构建文件夹复制到发布文件夹才能工作。通过 Blazor 在 wwwroot 文件夹中使用的图像虽然没有问题。
发布命令:

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

build exe (x64) 文件可以在 in\x64 中找到 释放 et6.0-windows10.0.19041\win10-x64\publish\


0
投票

1- 将

<WindowsPackageType>
节点添加到您的 .NET MAUI csproj 文件:

<WindowsPackageType Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">None</WindowsPackageType>

2- 在您的 launchSettings.json 中将

commandName
设置为
Project

3-以

Release
模式构建您的项目

4- 右键单击项目 -> 在文件资源管理器中打开文件夹

5- exe文件位于:bin -> Release -> net7.0-windows10.0.19041.0 -> win10-x64

© www.soinside.com 2019 - 2024. All rights reserved.