skip to Main Content

For the last few weeks I am trying to set up a project in VSCode to be able to build & run the windows desktop app. I understand that for WinUI 3 projects Visual Studio 2022 is recommended but most of the people in the team are using VSCode for all the projects. I was able to build & run WinUI / MAUI / UNO projects in Visual Studio 2022 but not able to do the same in VSCode.

None of the Microsoft documentation clearly denotes if it’s possible to run these technologies in VSCode. Or only Visual Studio 2022 is required to run any type of WinUI 3 projects for developing Windows Desktop apps.

I would like to know if it’s possible and if yes could anyone share the git repo of any WinUI projects that can run in VSCode and hope I can see the launch settings in the .vscode folder and other project config files subjected to change to get it work.

Just to reproduce, all I did was create a WinUI 3 / MAUI / UNO project in Visual Studio 2022 using templates available and try to run the same in VSCode. No workaround so far. Any best help is much appreciated.

WinUI 3 project shared in git repo,
https://github.com/to-marss/WinUI3TestRunInVSCode-

Work fine in Visual Studio 2022 but not in VS Code. This repo can be used to reproduce the issue. Please feel free to modify code changes to this repo for this trial in VSCode.

dotnet build / run returns error below,

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    Finally, yes VSCode can be used to run WinUI 3 apps.

    In the WinUI csproj, please make sure you add these properties in the property group,

     - <Platform>x64</Platform> (Required for VSCode)
     - <Platforms>x86;x64;arm64</Platforms> (Required for Visual Studio)
     - <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
     (Required for exe)
    

    It's ok to have both Platform and Platforms in the same project. Perhaps, having the common architecture would be an ideal way. In my case I preferred to go with X64 for both Platform and Platforms (based on my requirement).

    Please also add launch.json & tasks.json in .vscode folder (as in, https://github.com/to-marss/WinUI3TestRunInVSCode-)

    launch.json

    {
    "version": "0.2.0",
    "configurations": [
        {
            // Use IntelliSense to find out which attributes exist for C# debugging
            // Use hover for the description of the existing attributes
            // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
            "name": ".NET Core Launch (console)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            // If you have changed target frameworks, make sure to update the program path.
            "program": "${workspaceFolder}/WinUI3TestRunInVSCode/bin/x64/Debug/net6.0-windows10.0.19041.0/win10-x64/WinUI3TestRunInVSCode.exe",
            "args": [],
            "cwd": "${workspaceFolder}/WinUI3TestRunInVSCode",
            // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
            "console": "internalConsole",
            "stopAtEntry": false
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach"
        }
    ]
    

    }

    tasks.json

    {
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/WinUI3TestRunInVSCode/WinUI3TestRunInVSCode.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "publish",
            "command": "dotnet",
            "type": "process",
            "args": [
                "publish",
                "${workspaceFolder}/WinUI3TestRunInVSCode/WinUI3TestRunInVSCode.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "watch",
            "command": "dotnet",
            "type": "process",
            "args": [
                "watch",
                "run",
                "--project",
                "${workspaceFolder}/WinUI3TestRunInVSCode/WinUI3TestRunInVSCode.csproj"
            ],
            "problemMatcher": "$msCompile"
        }
    ]
    

    }

    With this setup we can use dotnet cli commands to build and run the app from VSCode. We can do the commands below,

    1. dotnet build - Build the libraries.
    2. dotnet run - Run the exe and app is displayed.
    3. dotnet watch - To have the hot reload behavior, update changes on runtime.
    4. dotnet publish - To publish the app.

    P.S. This works fine for any WinUI3 apps and UNO's WinUI target. I hope same can be achieved in MAUI with the minor .csproj changes as above. Hope this helps!


  2. According to the Microsoft document, the document shows that Developing native, cross-platform .NET Multi-platform App UI (.NET MAUI) apps requires Visual Studio 2022 17.3 or greater, or Visual Studio 2022 for Mac 17.4 or greater.

    Then I found the discussion on the GitHub shows that for now you can not develop the MAUI project on the VSCode platform. But you can use the cli to run the project on emulator.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search