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.

 

Published Friday, September 02, 2005 2:30 PM by ScottGu

Comments

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

Sunday, September 11, 2005 9:11 AM by POLARIS
Oh,yes,i read about custom ProfileProvider for Access database which can store ueser profile data in MSDN 2005.
But i feel it so diffculty to build for me.For example,To building custom ProfileProvider must implement many methods which be defined in SettingsProvider,ProfileProvider and so on.And it must implement some extraordinary assist methods for Profile properties.It's very complicated.
Would you tell me some easy methods to build custom ProfileProvider for Access database?Especially,it doesn't build some extraordinary assist method for Profile perperties.In other word,the custom ProfileProvider can be uesed to deal with all Profile properties.
Thanks a lot.
i come from China and English is pool.
My Email is tom_polaris@tom.com.Contacts me.

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

Sunday, September 11, 2005 11:34 AM by scottgu
Hi Tom,

Build providers are actually somewhat different from the application service providers that are also new in ASP.NET 2.0. Build Providers are for compiling individual resources within a web project.

The good news is that we have a sample already built that you can look at to learn how to build a Profile provider for Access. Just download the sample pointed to here: http://weblogs.asp.net/scottgu/archive/2005/08/01/421275.aspx

Hope this helps,

Scott

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

Monday, September 12, 2005 11:10 AM by POLARIS
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.


# [TIP] Installing ASP.NET 2.0 Membership, Personalization schema remotely

Wednesday, July 19, 2006 1:26 PM by Inside and Out...

I recently updated www.wintoolzone.com to use ASP.NET 2.0's Membership API, amongst other things. Now,...

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

Tuesday, August 29, 2006 7:25 AM by casper
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)

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

Wednesday, August 30, 2006 1:48 AM by ScottGu

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

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

Wednesday, August 30, 2006 8:32 AM by casper
Hi..Scott Thank very much you.. I think that I have already found another way.. http://www.codeproject.com/dotnet/TransformCodeGenerator.asp Casper

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

Thursday, February 22, 2007 5:11 AM by Christian

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?

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

Friday, February 23, 2007 1:32 AM by ScottGu

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

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

Friday, February 23, 2007 4:38 AM by Christian

Ok, that would be great! I have a public email at superzapper@gmail.com that you are welcome to hand out. Some samples would be perfect to get me started.

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

Monday, February 26, 2007 7:00 AM by Christian

Hi again. Just wanna hear if you passed my email (superzapper@gmail.com) along to someone who could tell me about custom file providers.

Im going on my last few days with my compagny before i switch jobs, so i have some time to look at it these days.

I dont mean to be stressing - im just excited about the prospects :-)

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

Tuesday, February 27, 2007 12:17 AM by Ariel Yang

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.

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

Tuesday, February 27, 2007 12:37 AM by Ariel Yang

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

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

Tuesday, February 27, 2007 3:01 AM by ScottGu

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

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

Sunday, March 18, 2007 2:31 PM by Doug Mayer

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

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

Monday, March 19, 2007 2:32 AM by ScottGu

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

# Email Filtering Service

Saturday, December 08, 2007 11:06 AM by Email Filtering Service

Having a road to volumes of data relating to this is unequaled.

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

Friday, August 08, 2008 6:11 AM by DotNetKicks.com

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# Usando Profile em um Web Application Project | :: Carlos Alessandro Ribeiro ::

Pingback from  Usando Profile em um Web Application Project | :: Carlos Alessandro Ribeiro ::