to-*_*ars 5 uno visual-studio-code winui-3 maui
我正在尝试在 VSCode 中建立一个项目来构建和运行 Windows 桌面应用程序:WinUI / MAUI / UNO,因为我们的团队主要使用 VSCode。
我知道 WinUI 3 项目建议使用 Visual Studio 2022 Microsoft 文档都没有明确指出
我使用可用模板在 Visual Studio 2022 中创建了一个工作示例 WinUI 3 项目。我尝试在 VSCode 中运行此示例失败(请参阅下面的错误)。到目前为止还没有解决方法。任何帮助深表感谢。
请随意修改我的示例代码/存储库以使其在 VSCode 中运行。
dotnet build / run 返回以下错误,
如果是
Finally, yes VSCode can be used to run WinUI 3 apps.
在 WinUI csproj 中,请确保在属性组中添加这些属性,
- <Platform>x64</Platform> (Required for VSCode)
- <Platforms>x86;x64;arm64</Platforms> (Required for Visual Studio)
- <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
(Required for exe)
Run Code Online (Sandbox Code Playgroud)
在同一个项目中可以同时拥有平台和平台。也许,拥有共同的架构将是一种理想的方式。就我而言,我更愿意为 Platform 和 Platforms 选择 X64(根据我的要求)。
还请在 .vscode 文件夹中添加 launch.json 和tasks.json(例如,https://github.com/to-marss/WinUI3TestRunInVSCode-)
启动.json
- <Platform>x64</Platform> (Required for VSCode)
- <Platforms>x86;x64;arm64</Platforms> (Required for Visual Studio)
- <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
(Required for exe)
Run Code Online (Sandbox Code Playgroud)
任务.json
{
"version": "0.2.0",
"configurations":[{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// if target frameworks was changed, update program path.
"program":
"${workspaceFolder}/WinUI3TestRunInVSCode/bin/x64/Debug/net6.0-windows10.0.19041.0/win10-x64/WinUI3TestRunInVSCode.exe",
"args": [],
"cwd": "${workspaceFolder}/WinUI3TestRunInVSCode",
// 'console' field https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}]
}
Run Code Online (Sandbox Code Playgroud)
通过此设置,我们可以使用 dotnet cli 命令从 VSCode 构建和运行应用程序。我们可以执行以下命令,
PS 这适用于任何 WinUI3 应用程序和 UNO 的 WinUI 目标。我希望通过对 .csproj 进行上述细微更改,可以在 MAUI 中实现同样的效果。希望这可以帮助!
| 归档时间: |
|
| 查看次数: |
3728 次 |
| 最近记录: |