Generating Code During Compilation

posted on 2005-06-08 at 10:31:47 by Joel Ross

I just sat through a breakout session at Tech Ed about the internals of ASP.NET 2.0, and saw a really cool feature. You can create your own build providers and tell it to handle a certain type of file. In the build provider, you can read that file and use whatever process you want to generate code to be compiled.

As an example, you could create a build provider for an XSD file and generate a class from that.

But this got me thinking. I also sat in on Scott Hanselman's code generation talk yesterday, and he uses WSDL and XSD files to generate a lot of his code. He also uses CodeSmith to generate the files. Right now, he generates them as .g.cs files so everyone knows it's generated.

Now, though, you could take his process, and generate code at compile time, meaning there's never a need to have the files written to the file system, or generate the .build files for Nant. That's very cool.

Categories: ASP.NET