Perhaps you could do something with MSBuild by creating a custom project goal that does the job, but I never did.
What I did recently, which is now available on the ASP.NET 5 platform based on DNX, is a concept known as meta-programming. I wrote an article in a blog article about this concept specifically with examples of code generation at compilation time. In my specific example, I have a class that will not compile, but then with the introduction of ICompileModule I can populate the missing return at compile time.
This is possible because in DNX-based applications, the RoslynCompiler class actually supports loading instances of ICompileModule at compile time, and then starts those instances before your main project compilation. This allows you to add / remove / replace syntax trees in the compilation before the compiler finishes its work.
If you plan to develop on ASP.NET 5, this may allow you to do what you need, but I do not know how you will do it.
It seems quite ascetic for me.
I asked a question in which I also answered myself about the development of a compilation solution that performs code generation for another scenario:
Getting interface implementations in reference assemblies with Roslyn
And finally, other examples where this can be useful, and with something I worked with, is the ability to create migration classes of the EF class from .sql files embedded in my assemblies. All of these scenarios are now easier to implement on ASP.NET 5 + Roslyn.
source share