You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用.NET CLI运行.NET MAUI应用程序?

<ItemGroup>
    ...
</ItemGroup>
```

launchSettings.json配置如下:

{
  "profiles": {
    "Windows Machine": {
      "commandName": "MsixPackage",
      "nativeDebugging": false
    }
  }
}

通过Visual Studio可正常创建并运行该项目,但使用.NET CLI执行时:

  • dotnet build ./MauiCliBasic.csproj执行正常
  • 执行dotnet run --project ./MauiCliBasic.csproj报错:

The launch profile "(Default)" could not be applied.
A usable launch profile could not be located.
Unable to run your project
Your project targets multiple frameworks. Specify which framework to run using '--framework'.

指定框架后执行dotnet run --project ./MauiCliBasic.csproj --framework net6.0-windows10.0.19041.0,仍报错:

The launch profile "(Default)" could not be applied.
A usable launch profile could not be located.

请问遗漏了什么配置?

解决方案

1. 命令行直接指定启动配置

dotnet run需要明确绑定启动配置,执行命令时添加--launch-profile参数,指定已有的"Windows Machine"配置即可:

dotnet run --project ./MauiCliBasic.csproj --framework net6.0-windows10.0.19041.0 --launch-profile "Windows Machine"

2. 完善launchSettings.json配置

在配置文件中为每个目标框架添加明确的targetFramework关联,让CLI能自动匹配对应配置:

{
  "profiles": {
    "Windows Machine": {
      "commandName": "MsixPackage",
      "nativeDebugging": false,
      "targetFramework": "net6.0-windows10.0.19041.0"
    },
    "Android": {
      "commandName": "Project",
      "launchBrowser": false,
      "targetFramework": "net6.0-android"
    }
  }
}

修改后执行指定框架的dotnet run命令,无需额外添加--launch-profile参数即可自动匹配。

3. 调整启动方式(可选)

如果不需要通过MSIX包运行Windows项目,可将commandName改为Project,直接启动项目:

"Windows Machine": {
  "commandName": "Project",
  "nativeDebugging": false,
  "targetFramework": "net6.0-windows10.0.19041.0"
}

这种方式更轻便,适合开发调试场景。


内容的提问来源于stack exchange,提问作者VivekDev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 01:15:46