The Source Code Generation Game with Steve Collins

There has been a lot of buzz around the introduction of source code generators in .NET 5 and Microsoft has been building on this in .NET 6 and there is more to come in .NET 7.

But, how did we get here and what may the future hold?

Starting with the question of "What is code generation?", I present a brief history of my journey into source code generation, starting with the ZX Spectrum (a program published in a UK magazine to convert machine code into BASIC DATA statements), through the Visual Basic 3-6 years (VB code created when element clicked upon; tools to generate VB from SQL tables and stored procs).

I will then move on to do a whistle-stop tour of:

How .NET introduced tooling in Visual Studio for code-generation for SOAP Service Reference clients, RESX resources, and the pitfalls of the code generated
How previously, most code generation has been template based using external tooling run outside VS to generate files that need to be manually included in .NET projects to compile
Introduction of T4 templates in Visual Studio (leading onto .NET Core's dotnet new command-line templates)
Code generation "on-the-fly" in Regular Expressions (intermediate code or compile to MSIL) and Entity Framework (SQL statement generation)
IL Weaving vs Source Code Generation
The latest version of service reference code generation for REST and gRPC
The remainder of the talk will focus on the source generators introduced with .NET 5 and 6, covering:

How they differ from traditional template-based code generation by being part of the compilation process
Tooling to help with debugging in Visual Studio
Gotchas with the tooling in Visual Studio!
Unit testing code generation
Microsoft's use of generators in .NET 6
Lastly, we will look at where source generators may go in the future

Enhancements proposed for .NET 7
AI-enhanced code generation with Intellicode and GitHub Copilot integration?
"Computer make it so" - Experiments being done in AI-generated code without a template or specification
Steve Collins is an independent software developer/architect with over 25 years of experience in the industry working with Microsoft technologies.

He blogs at, tweets @stevetalkscode, and is an organizer of the Milton Keynes .NET User Group.

You may have caught Steve's previous talks at user groups and conferences around the UK or heard him on episodes of the Dot Net Core Show and the Unhandled Exception podcasts.
An error has occurred. This application may no longer respond until reloaded. Reload 🗙