The (lack of) IDesignerHost in Visual Studio 2008 (Orcas) ASP.NET Web pages

My article HOWTO: Getting IDesignerHost and IHTMLDocument of WebForms from a Visual Studio .NET add-in explained how to do this with VS.NET 2002/2003/2005, but if you have tried it, it doesn’t work with VS 2008 (there is no IServiceProvider here). The underlying reason is that the new ASP.NET/HTML designer is based on the FrontPage editor, not in the old Internet Explorer editor (MSHTML, aka “Trident”). See:

http://blogs.msdn.com/mikhailarkhipov/archive/2007/01/20/sapphire-new-web-form-designer-in-visual-studio-orcas.aspx

FrontPage is now deprecated but Microsoft used its HTML editor in two new products: the SharePoint 2007 Designer and Expression Web:

http://office.microsoft.com/en-us/frontpage/default.aspx

The EnvDTE.HtmlWindow.CurrentTabObject property returns a “DispDesignerDocument” object that initially I thought belonged to the SharePoint Designer assemblies but the cast failed, and after some hours I discovered that it belongs to Expression Web, so you have to add a reference to the C:\Program Files\Microsoft Web Designer Tools\VWDFPEDITAX.DLL file (use the Browse tab) to generate two interop assemblies (Interop.Microsoft.VisualWebDeveloper.Interop.WebDeveloperInternal and Interop.Microsoft.VisualWebDeveloper.Interop.WebDeveloperPage). See:

http://blogs.msdn.com/mikhailarkhipov/archive/2007/08/20/what-is-microsoft-visual-studio-web-authoring-component.aspx

And while it seems that the Expression Web reference model is not documented, I guess it’s pretty much the same than the one of SharePoint Designer 2007, which is documented:

SharePoint Designer 2007 Developer Reference
http://msdn2.microsoft.com/en-us/library/bb149147.aspx

The interesting part is that the new HTML parser returns elements for both HTML and ASP.NET controls (in the previous versions you had to use MSHTML to get the HTML controls, and IDesignerHost to get the ASP.NET controls, because it seems that <asp> tags were alien to the IE-based editor). Also, as far as I know after a lot of research, there is no IDesignerHost in VS 2008 for ASP.NET Web pages (there wasn’t either in previous versions of VS for HTML pages, only for ASP.NET pages). Internally, Visual Studio uses classes to encapsulate each HTML element or web control and provides PropertyDescriptors, TypeConverters, and CustomTypeDescriptors to interact with the Properties window and other VS areas. So, for the most part, at design-time ASP.NET controls act as HTML controls (and not as IComponent-based components), and ASP.NET Web pages act as pure HTML pages (which as I said, did not have IDesignerHost in previous versions of VS either), therefore providing a much appreciated unified model at the cost of some losses for some people that started with VS 2005:

ASP.NET v2.0: is the non-visual components support finally back?
http://weblogs.asp.net/cazzu/ComponentsNotBack