SuperAPI AI 工具集

building-code

编程与开发

查看项目

更新于 10-15 21:12

技能介绍

用途:指导如何还原并构建 dotnet/winforms 仓库,包括还原 NuGet 包、构建完整解决方案、构建单个项目,以及在 Visual Studio 和 VS Code 中构建。

前置条件:WinForms 运行时场景、测试执行和 Visual Studio 工作流需要 Windows;Linux 仅支持命令行还原/构建,需使用 build.sh 而非 build.cmd / Restore.cmd。IDE 构建需 Visual Studio 2022,所需工作负载见 WinForms.vsconfig。build.cmd 和 Restore.cmd 会自动使用 global.json 指定的仓库本地 .NET SDK,命令行构建无需机器级 SDK 安装。

还原:运行 .\Restore.cmd,其内部执行 eng\common\Build.ps1 -NativeToolsOnMachine -restore,可在其后附加 Build.ps1 标志,如 .\Restore.cmd -configuration Release。

完整解决方案构建(推荐):运行 .\build.cmd,默认还原并构建 Winforms.sln(Debug|Any CPU),内部执行 eng\common\Build.ps1 -NativeToolsOnMachine -restore -build -bl。常用标志包括 -configuration/-c、-platform、-restore/-r、-build/-b、-rebuild、-clean、-pack、-bl/-binaryLog、-ci、-test/-t、-integrationTest。示例:.\build.cmd -configuration Release、.\build.cmd -test、.\build.cmd -pack。

单项目快速构建:在至少一次完整还原成功后,用 dotnet build 只重建有改动的项目,例如 dotnet build src\System.Windows.Forms\System.Windows.Forms.csproj,测试项目同理,可用 -c Release。需确保仓库本地 SDK 在 PATH 中,可先运行 .\start-code.cmd 或 .\start-vs.cmd,或先运行 .\Restore.cmd。

Visual Studio:先运行 .\Restore.cmd,再运行 .\start-vs.cmd 打开 Winforms.sln,正常构建。VS Code:可选 .\Restore.cmd,运行 .\start-code.cmd 打开工作区,在集成终端执行 .\build.cmd 或 dotnet build <project>。

构建产物:二进制位于 artifacts\bin<Project>\Debug<tfm>\,日志位于 artifacts\log\,二进制日志为 artifacts\log\Debug\Build.binlog,测试结果位于 artifacts\TestResults\,NuGet 包位于 artifacts\packages\。排查构建错误可用 MSBuild Structured Log Viewer 查看 .binlog。

限制与排查:多数错误为编译错误,按常规修复;MSBuild 任务错误查看 Build.binlog;SDK 版本不匹配时运行 .\Restore.cmd;使用非预览版 VS 时需在工具→选项→环境→预览功能中启用 .NET SDK 预览版。