#MSBuild In Depth
Building, Extending, and Debugging .NET Builds

##Every .NET build runs through MSBuild
Every dotnet build, every press of F5, every dotnet pack that produces a NuGet package, and every CI pipeline that turns a commit into a shippable artifact runs through MSBuild. Yet for most developers it stays a black box: a .csproj file you edit by copying snippets from the internet, and a build that either works or fails for reasons that are hard to see.
This book opens that box. It starts with the engine's two phases, evaluation and execution, and the four concepts every build file is made of: properties, items, targets, and tasks. From there it scales up to real repositories, custom build logic written in C#, packaging, and reproducible CI.
Its through-line is observability. The diagnostic tools are not tucked into a final chapter. Binary logs, the MSBuild Structured Log Viewer, and the command-line switches that print what evaluation decided arrive in Part II, right after the foundations, and are used in every part that follows. You stop reasoning about builds from their source, and start answering "why did this rebuild?" from evidence.
##What you will be able to do
- Read any
.csproj, .props, or .targets file, and know which tool to reach for when an import or an SDK target changes the answer - Explain evaluation and execution well enough to predict the engine instead of guessing
- Structure real repositories with
Directory.Build.props, central package management, and multi-targeting - Extend the build with your own targets, custom C# tasks, inline tasks, and build-time code generation
- Debug from evidence: capture a binlog, read it in the Structured Log Viewer, and query evaluated properties and items
- Diagnose and fix broken incrementality, and cut build time where it goes
- Ship build logic to other people in a NuGet package or a project SDK
- Make builds reproducible in CI/CD, with a pinned SDK and a binlog captured on every run
##Who this book is for
The intermediate .NET developer who is comfortable in C# and at a terminal, edits project files occasionally, and has never been taught how MSBuild works. If you have ever pasted a <Target> into a .csproj and hoped, this book is for you. It is equally aimed at build and DevOps engineers maintaining large or slow builds, and at library and SDK authors who ship props and targets to other people. No prior knowledge of MSBuild internals is assumed.
Six parts, 32 chapters, and eleven appendices, including a symptom index that takes you from a broken build to the right command and the right chapter, a full command-line reference, and a reference for reserved properties, item metadata, and property functions. Everything targets the .NET 10 SDK. Listings are read from real, compiled sample projects when the book is built, and the samples are available as a download.
##Table of contents
Part I: Foundations
- What Is MSBuild?
- Project File Anatomy
- Properties
- Items and Item Metadata
- Targets and the Build Process
- Tasks
Part II: Seeing What MSBuild Did
- Reading Build Output
- Binary Logs (binlog)
- The MSBuild Structured Log Viewer
- Preprocessing and Evaluation Debugging
Part III: Structuring Real Projects
- Imports: .props and .targets Files
- Directory.Build.props and .targets
- Solutions and the Build Graph
- Configurations, Platforms, Multi-Targeting
- Common SDK Properties & Customization
Part IV: Extending MSBuild
- Writing Inline Build Logic in Project Files
- Custom Tasks in C#
- Debugging Custom Tasks
- Code-Generation Builds
- Inline Tasks with RoslynCodeTaskFactory
- Shipping Build Logic in NuGet Packages
- Authoring Project SDKs
Part V: Performance and Production
- Performance and Incrementality
- Restore, NuGet, and MSBuild
- Packing and Publishing
- MSBuild in CI/CD
- Cross-Platform and Toolchain Concerns
Part VI: Advanced Patterns and Legacy
- Hosting and Programming the MSBuild API
- Advanced Evaluation and Metaprogramming
- Anti-Patterns and Field Recipes
- Migrations and Legacy
- Where to Go Next
Appendices
- Appendix A: Command-Line Reference
- Appendix B: Reserved & Well-Known Properties and Metadata
- Appendix C: Property & Item Function Reference
- Appendix D: Diagnostic Environment Variables
- Appendix E: Binlog & Viewer Search-Syntax Quick Reference
- Appendix F: Querying Binlogs with an MCP Server
- Appendix G: Multithreaded Task Execution
- Appendix H: Symptom Index
- Appendix I: Glossary
- Appendix J: Further Resources
- Appendix K: Exercise Notes
##Get the book