Skip to content

附录 B:命令清单

下面这些命令覆盖了你在主案例里最常做的几件事:运行示例、构建项目、跑测试、查看生成文件。

场景命令用途
运行示例dotnet run --project .\sample\01-tostring-generator\ToStringGenerator.Sample\ToStringGenerator.Sample.csproj直接观察生成后的 ToString() 输出
构建示例dotnet build .\sample\01-tostring-generator\ToStringGenerator.Sample\ToStringGenerator.Sample.csproj只构建,不运行,适合先看 .g.cs
构建整个案例dotnet build .\sample\01-tostring-generator\ToStringGenerator.slnx同时构建生成器、示例和测试工程
运行测试dotnet test .\sample\01-tostring-generator\ToStringGenerator.Tests\ToStringGenerator.Tests.csproj验证生成结果没有退化
查看案例目录Get-ChildItem .\sample\01-tostring-generator先确认项目结构
查看生成文件Get-ChildItem .\sample\01-tostring-generator\ToStringGenerator.Sample\obj\Debug\net8.0\generated -Recurse找到实际生成的 .g.cs
打开生成文件目录ii .\sample\01-tostring-generator\ToStringGenerator.Sample\obj\Debug\net8.0\generated在资源管理器里直接打开生成目录
查看详细构建日志dotnet build .\sample\01-tostring-generator\ToStringGenerator.Sample\ToStringGenerator.Sample.csproj -v normal排查生成器是否参与编译、查看详细构建输出

最常用的三条命令

powershell
dotnet build .\sample\01-tostring-generator\ToStringGenerator.Sample\ToStringGenerator.Sample.csproj
dotnet run --project .\sample\01-tostring-generator\ToStringGenerator.Sample\ToStringGenerator.Sample.csproj
dotnet test .\sample\01-tostring-generator\ToStringGenerator.Tests\ToStringGenerator.Tests.csproj

推荐使用顺序

  1. dotnet build
  2. 再去看 obj/generated
  3. 然后 dotnet run
  4. 最后 dotnet test

基于当前仓库文档副本构建的 VitePress 站点