简体   繁体   English

我可以使用 VSCode 开发 WINDOW 使用 WinUI 3 或 MAUI 或 UNO 堆栈的桌面应用程序吗?

[英]Can I use VSCode for developing WINDOW DESKTOP Apps using WinUI 3 or MAUI or UNO stack?

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.在过去的几周里,我试图在 VSCode 中建立一个项目,以便能够构建和运行 windows 桌面应用程序。 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.我知道对于 WinUI 3 项目,建议使用 Visual Studio 2022,但团队中的大多数人都在所有项目中使用 VSCode。 I was able to build & run WinUI / MAUI / UNO projects in Visual Studio 2022 but not able to do the same in VSCode.我能够在 Visual Studio 2022 中构建和运行 WinUI / MAUI / UNO 项目,但无法在 VSCode 中执行相同的操作。

None of the Microsoft documentation clearly denotes if it's possible to run these technologies in VSCode .没有任何 Microsoft 文档明确表示是否可以在VSCode中运行这些技术。 Or only Visual Studio 2022 is required to run any type of WinUI 3 projects for developing Windows Desktop apps .或者仅需要 Visual Studio 2022 即可运行任何类型的 WinUI 3 项目以开发 Windows 桌面应用程序

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.我想知道这是否可能,如果可以,任何人都可以共享可以在 VSCode 中运行的任何 WinUI 项目的 git 存储库,并希望我可以看到 .vscode 文件夹中的启动设置和其他经过更改的项目配置文件以获取它工作。

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.只是为了重现,我所做的就是使用可用模板在 Visual Studio 2022 中创建一个 WinUI 3 / MAUI / UNO 项目,并尝试在 VSCode 中运行相同的项目。 No workaround so far.到目前为止没有解决方法。 Any best help is much appreciated.非常感谢任何最好的帮助。

WinUI 3 project shared in git repo, https://github.com/to-marss/WinUI3TestRunInVSCode- WinUI 3 项目共享在 git repo, https://github.com/to-marss/WinUI3TestRunInVSCode-

Work fine in Visual Studio 2022 but not in VS Code.在 Visual Studio 2022 中运行良好,但在 VS Code 中运行不佳。 This repo can be used to reproduce the issue.这个 repo 可以用来重现这个问题。 Please feel free to modify code changes to this repo for this trial in VSCode.请随时在 VSCode 中针对此试用版修改此存储库的代码更改。

do.net build / run returns error below, do.net 构建/运行在下面返回错误,

在此处输入图像描述

Finally, yes VSCode can be used to run WinUI 3 apps.最后,是的,VSCode 可用于运行 WinUI 3 应用程序。

In the WinUI csproj, please make sure you add these properties in the property group,在 WinUI csproj 中,请确保在属性组中添加这些属性,

 - <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.在同一个项目中同时拥有 Platform 和 Platforms 是可以的。 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).在我的例子中,我更喜欢 go 和 X64 平台和平台(根据我的要求)。

Please also add launch.json & tasks.json in.vscode folder (as in, https://github.com/to-marss/WinUI3TestRunInVSCode- )还请在 .vscode 文件夹中添加 launch.json & tasks.json (如https://github.com/to-marss/WinUI3TestRunInVSCode-

launch.json启动.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任务.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 do.net cli commands to build and run the app from VSCode.通过此设置,我们可以使用 do.net cli 命令从 VSCode 构建和运行应用程序。 We can do the commands below,我们可以执行以下命令,

  1. do.net build - Build the libraries. do.net build - 构建库。
  2. do.net run - Run the exe and app is displayed. do.net run - 运行 exe 并显示应用程序。
  3. do.net watch - To have the hot reload behavior, update changes on runtime. do.net watch - 要具有热重载行为,请在运行时更新更改。
  4. do.net publish - To publish the app. do.net publish - 发布应用程序。

PS This works fine for any WinUI3 apps and UNO's WinUI target. PS 这适用于任何 WinUI3 应用程序和 UNO 的 WinUI 目标。 I hope same can be achieved in MAUI with the minor.csproj changes as above.我希望在 MAUI 中通过上述 minor.csproj 更改也能实现同样的效果。 Hope this helps!希望这可以帮助!

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.根据微软文档,该文档显示开发本机、跨平台 .NET 多平台 App UI (.NET MAUI) 应用程序需要 Visual Studio 2022 17.3 或更高版本,或者 Visual Studio 2022 for Mac 17.4 或更高版本。

Then I found the discussion on the GitHub shows that for now you can not develop the MAUI project on the VSCode platform.然后发现GitHub上的讨论显示暂时不能在VSCode平台上开发MAUI项目。 But you can use the cli to run the project on emulator.但是您可以使用 cli 在模拟器上运行项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM