Appearance
附录 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推荐使用顺序
- 先
dotnet build - 再去看
obj/generated - 然后
dotnet run - 最后
dotnet test