我如何将一个.net MAUI应用程序发布为单个可执行文件?这是可能的吗? 我有一个应用程序,我希望我的朋友们能在他们的Windows PC上使用。是否有任何方法可以不使用命令提示符来实现?
我如何将一个.net MAUI应用程序发布为单个可执行文件?这是可能的吗? 我有一个应用程序,我希望我的朋友们能在他们的Windows PC上使用。是否有任何方法可以不使用命令提示符来实现?
随着 .NET MAUI 6.0.400 (服务发布 1) 的新版本发布,您可以将应用程序构建为可工作的 exe 文件。
在 Visual Studio 中:
右键单击解决方案并在终端中打开。
运行以下命令:
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
可在 \bin\x64\release\net6.0-windows10.0.19041\win10-x64 中找到构建 exe(x64)文件。
发布为单个文件是可能的,但目前存在一些小问题,例如需要将图像从构建文件夹复制到发布文件夹才能正常工作。位于 wwwroot 文件夹中通过 Blazor 使用的图像则没有问题。
发布命令:
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
可执行文件(x64)位于 \bin\x64\release\net6.0-windows10.0.19041\win10-x64\publish\ 目录下。
1- 在您的 .NET MAUI csproj 文件中添加一个 <WindowsPackageType>
节点:
<WindowsPackageType Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">None</WindowsPackageType>
2- 在你的 launchSettings.json 中将 commandName
设置为 Project
3- 在Release
模式下构建您的项目dotnet publish
之后,也可以正常工作。 - Salar