3

With typical web apps we do the following.

dotnet new webapp --name ./MyNewWebApp --framework net6.0

cd MyNewWebApp

dotnet build ./MyNewWebApp.csproj

dotnet run --project ./MyNewWebApp.csproj

And it works. Now I trying to play around with dotnet MAUI projects.

With MAUI the project file is complex when compared to a web project.

It has multiple target frameworks, and the csproj file looks as follows.

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
        <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
        <!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
        <!-- <TargetFrameworks>$(TargetFrameworks);net6.0-tizen</TargetFrameworks> -->
        <OutputType>Exe</OutputType>
        ...
</PropertyGroup>

    <ItemGroup>
        ...
    </ItemGroup>

</Project>

Further more, the launchSettings.json file is quite simple.

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

With visual studio I am able to create and run them. The Visual Studio launch tool bar shows the following.

Visual Studio Tool bar for running the MAUI app

So now with MAUI project, build command works fine.

dotnet build ./MauiCliBasic.csproj

But when I execute the run command, I get the following errors.

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'.

And when I specify the framework I still get the errors.

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.

So what am I missing?

running dotnet MAUI project from command line

VivekDev
  • 20,868
  • 27
  • 132
  • 202

1 Answers1

1

This is a known issue that being tracked in these two threads: Unable to run Windows application from command line , Unable to run Windows application from .NET SDK command line, feel free to follow up with them. BTW, it might be related to the settings in the launchSettings.json file. You can refer to Error after modifying launchSettings: The launch profile "(Default)" could not be applied.

Alexandar May - MSFT
  • 6,536
  • 1
  • 8
  • 15