Building Custom Build Providers with ASP.NET 2.0 and VS 2005

One of the cool new features in ASP.NET 2.0 is support for what we call "build providers".  These are providers that can plug into the ASP.NET compilation system and provide custom compilation support for file-types.  ASP.NET ships with a number of built-in providers in the box -- including support for .wsdl and .xsd files.  These providers can automatically generate the appropriate proxy or dataset class for you without you having to manually generate code and keep it in sync with the declarative format (I believe they also generate as partial types -- so you can add your own object model and methods to extend them).

Here are two good blog articles that walkthrough building and adding your own custom build provider: http://blogs.msdn.com/kaevans/archive/2005/09/02/460231.aspx and http://pluralsight.com/blogs/fritz/archive/2004/09/06/2188.aspx

As you can see in the screenshots in them, in addition to getting runtime build support, you'll also get intellisense support in VS 2005. 

In the beginning of the Whidbey project there was a plan to enable broad declarative support for file-types as compiler inputs (for example: XAML could have been processed this way).  Unfortunately due to time/resources the compiler teams had to scale back their support for this -- and only web projects still contain them.  I'm hoping we'll see broader support for them in all project types with future releases.

 

10 Comments

  • Thank you.

    I read the article and codes about Profile provider for Access. And I implemented the custom Profile provider for Access database.

    Thanks again.






  • Does the Build Providers works in web application project?
    I try it...but...failure
    Help me please...
    (The English degree is not good,Please forgive more)

  • Hi Casper,

    Build Providers work at runtime with ASP.NET when using the WAP project model -- but the types generated by build providers aren't available to the code-behind classes of the WAP project (since they get compiled after the WAP project compiles).

    Hope this helps,

    Scott

  • Hi Scott, thanks for a great blog - i always seem to end up here when i search google for interesting articles.

    I have made a simple buildprovider that creates custom entities from an xml-file that contains info about what to create (ClassName, DataBase to query, SELECT statement - you get the picture). This all works great with my website project, but i would like to use it in a webapplication project as well.

    The problem is that the webapp. project doesn't contain the App_Code folder where i am supposed to drop my xml-file - is there another way to do this with webapplication projects?



  • Hi Christian,

    You can't use a build provider from the code-behind of a web application project, because it is compiled after the web application project is.

    Instead, what you might want to look at doing is building a custom file provider for VS. This would allow you to generate code within the project everytime you modified and saved your .XML file. If you want to send me email I can loop you in with someone who can point at some samples on how to-do this.

    Thanks,

    Scott

  • Hi Scott. I'm very intrested in generating code using Custom Build Provider, but it seems that this techology could only been used in a WebSite Project.

    Can I use it in a Web Application Project?

    If not, Custom Tool feature in VS 2005 may be an alternative solution I think.

  • I'm sorry, Scott. I didn't read above comments carefully. I think I have already got the answer from the comments.

  • Hi Christian,

    Sorry for the delay in getting back to you - I just sent you an email to help find some samples on this.

    Thanks,

    Scott

  • Hi Scott,

    This post is great. I've been interested in custom build providers for a while now and just recently could justify a good reason to use them. What I'm trying to do is create a class that will allow me to pull a particular SiteMapNode to redirect to its URL. I'd like to implement something of a MVC architecture using WebForms, and one of the cleanest ways I know of for the view to redirect to another page (using .NET 2.0) would be to have something available for compile-time checking that the page is there, etc. It would also allow to decouple the URL from the page.

    Anyway, do you know if it's possible to use a build provider for .sitemap? Setting the BuildProviderAppliesTo to Web or All won't pick it up unless it's in App_Code, but I want to be able to use Web.sitemap in the site's root.

    Thanks!
    Doug

  • Hi Doug,

    I believe you could build a custom build provider for .sitemap files. What you'd first want to-do is build a custom sitemap provider (independent of it running at compilation).

    Jeff Procise has a good article on how to-do this here: http://weblogs.asp.net/scottgu/archive/2006/01/11/435108.aspx

    Thanks,

    Scott

Comments have been disabled for this content.