如何从WinForms应用程序中打开MAUI应用程序
从WinForms应用中打开MAUI应用的实现方法
当然可以通过编程方式从WinForms应用内部打开MAUI应用——两者都是Windows平台的桌面应用,直接使用.NET的System.Diagnostics.Process类就能实现。
核心实现方式
- 定位MAUI应用的可执行文件路径(调试阶段用项目输出目录的exe,发布后用打包/发布生成的exe路径)
- 调用
Process.Start()方法启动该可执行文件
代码示例(WinForms按钮点击事件)
using System.Diagnostics; using System.IO; using System.Windows.Forms; private void btnLaunchMauiApp_Click(object sender, EventArgs e) { // 替换为你的MAUI应用exe的实际路径 string mauiExePath = @"C:\Projects\MauiApp1\bin\Release\net8.0-windows\win-x64\publish\MauiApp1.exe"; if (File.Exists(mauiExePath)) { Process.Start(new ProcessStartInfo(mauiExePath) { UseShellExecute = true }); } else { MessageBox.Show("未找到MAUI应用程序,请检查路径是否正确。"); } }
针对MSIX打包的MAUI应用
如果你的MAUI应用是打包成MSIX格式的,可以通过应用包名启动,示例如下:
private void btnLaunchMsixMauiApp_Click(object sender, EventArgs e) { // 替换为MAUI应用的实际包名,可在Package.appxmanifest中查看 string mauiPackageName = "MauiApp1_8wekyb3d8bbwe!App"; Process.Start(new ProcessStartInfo("explorer.exe", $"shell:AppsFolder\\{mauiPackageName}")); }
注意事项
- 确保WinForms应用有访问MAUI应用路径的权限,尤其是发布后的部署路径
- 调试阶段可以使用相对路径,但发布后建议使用绝对路径或通过配置文件管理路径
内容的提问来源于stack exchange,提问作者Gaurav Sharma
相关产品推荐
相关产品推荐

