views:

70

answers:

2

I have written a code generator using CodeDom and it generates a number of classes from stored procedures. I'd like to add its execution as a build step and then add all of its classes to the solution programatically at build-time.

How do I do this?

+1  A: 

Use Custom Build Providers

Subsonic also uses Build Providers to generate its DAL and code. Please check subsonic configuration for custom build provider. It is open source you can check its implementation also.

<configuration>
  <system.web>
    <compilation>
      <buildProviders>
        <add extension=".abp" type="SubSonic.BuildProvider, SubSonic"/>
      </buildProviders>
     </compilation>
  </system.web>
</configuration>

It uses .abp extension file to initiate its build provider.

Edit : Yes, Custom build providers are super feature of ASP.Net. But traditional winform or other developers can use MSBuild custom tasks to get the same effect. Dino Esposito has provided a great article for the same. You can check it here.

Mahin
That's very interesting! It seems as though these custom build providers only support web projects, though. Am I reading that right?
Chris McCall
You are right. Custom build providers are feature of ASP.Net. But you can use MSBuild custom tasks to get the same effect. Please check Edit to my answer.
Mahin
I ended up doing it as a custom task, which is the talk of the dept. Thanks!
Chris McCall
A: 

I don't know how this would work, but here goes:

If your CodeDOM code is generated in a separate project, generate the classes and then add the file names to the .csproj file (it's just XML) of a library. Have it ordered to build first as well. Then have the library's pre-build event run the code generating app, then it will compile. When you click on VS the next time, it will ask you to reload because the project file has changed and your new classes should show up.

It seems a little hacky, but with a little scripting it could be automated.

scottm