microsoft / vscode-dotnettools

This is a feedback repository to capture issues logged for the C# Dev Kit and related extensions from Visual Studio Code
Other
234 stars 13 forks source link

[Question] Using multiple projects in solution and selecting one for launch #1608

Closed RobertoMachorro closed 1 week ago

RobertoMachorro commented 1 week ago

I have two projects and both are in a solution file. I'd like to launch one by selecting it and release/debug. I have the configuration file below. When selecting any of the entries and starting, nothing happens in VSCode. When I remove the "project" property from any of the configurations, only the first project builds and runs.

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "App1 Debug",
            "type": "maui",
            "request": "launch",
            "preLaunchTask": "maui: Build",
            "project": "App1",
            "configuration": "Debug"
        },
        {
            "name": "App1 Release",
            "type": "maui",
            "request": "launch",
            "preLaunchTask": "maui: Build",
            "project": "App1",
            "configuration": "Release"
        },
        {
            "name": "App2 Debug",
            "type": "maui",
            "request": "launch",
            "preLaunchTask": "maui: Build",
            "project": "App2",
            "configuration": "Debug"
        },
        {
            "name": "App2 Release",
            "type": "maui",
            "request": "launch",
            "preLaunchTask": "maui: Build",
            "project": "App2",
            "configuration": "Release"
        }
    ]
}
emaf commented 1 week ago

@RobertoMachorro is there any reason for using custom launch configurations instead of selecting the startup project from the language status menu?

When you open the solution with a MAUI project, and then open a .cs or .csproj file in the editor, you should see {} in the right side of the status bar. See https://learn.microsoft.com/dotnet/maui/get-started/first-app?pivots=devices-windows&view=net-maui-9.0&tabs=visual-studio-code#choose-your-target-device.

RobertoMachorro commented 1 week ago

Thanks @emaf for your quick response.

I believe I had misunderstood the process, but based on what you said, the following worked for me:

I select the Target and Startup Project in the {} popup menu, and then hit F5, I get taken to the Run and Debug panel, I go through the prompts and it forces me to generate a launch.json. Rather than add all the stuff I had before, I went with the auto-generated config below:

{
    "configurations": [
        {
            "name": ".NET MAUI",
            "type": "maui",
            "request": "launch",
            "preLaunchTask": "maui: Build"
        }
    ]
}

At that point, anything I have in the {} popup menu (Target, Startup Project, Debug/Release) is what runs when I hit F5. Many thanks! 🙏

github-actions[bot] commented 1 week ago

@emaf, the 'needs-more-info' label has been removed upon receiving further response from the original bug filer.