Even easier single assembly modules

by: Allan Thræn

During the last year, both Dan and Johan has made some great posts showing how to fit an entire module into a single .dll file. I’ve been very fascinated by this approach. It’s so clean and nice to just be able to drop a single assembly in the bin folder and magically, the plugin will appear in your EPiServer – everything embedded in 1 file – and running from it. The only thing bothering me is the amount of manual work (I’ve never been a fan of that) involved in making such an assembly (in spite of the good & helpful guides Dan & Johan have provided). So, since I want to use this approach to a couple of upcoming projects I decided to once and for all make a single assembly that contains a self registrating Virtual Path Provider to embedded resources. The code is directly from http://www.codeproject.com/KB/aspnet/ASP2UserControlLibrary.aspx and Dan’s implementation, with very little modifications.

With this assembly in your bin folder, you can add any other module that has embedded content and not worry about it – just reference the content like this:

~/App_Resource/DebugPlugin.dll/DebugPlugin.Debug.ascx

so, that would be [App Root]/App_Resource/[Assembly name]/[Namespace].[filename of embedded content]. You can embed pretty much anything – images, aspx, ascx, javascript, css files and so on.

If you’re in doubt as to what the resource is called in your assembly you can use Reflector to browse the assembly’s resources.

Remember to set the “Build Action” in Visual Studio to “Embedded Resource” for every piece that you want to access this way, and remove the “CodeFile” attribute from the registration of aspx and ascx files, not to break VS.

Deploy this assembly together with your plugins – if it’s already in the bin folder you are installing to, it can be skipped. One copy of it is all your need…

Get it here (for EPiServer CMS 5 R2)

25 February 2009


Comments

  1. Good thinking. One think I have done is to allow / to work as dot. That way you can have user controll (~/App_Resource/DebugPlugin.dll/DebugPlugin/Debug.ascx) that can use other usercontrols directly [%@ Register src="OtherSideBar.ascx"....&] instead of the full path
  2. Nice idea! One downside however with this approach when doing edit/admin-mode plugins is that you dont get the default access control enforced through web.config ... /johan
  3. Johan: good point. I suppose we could extend it to also support ~/[UI Path]/App_Resource/ ...
  4. What default access control do you mean Johan? Putting custom plugins under /UI/ is not supported afaik.
  5. Steve, consider the following: [GuiPlugIn( PlugInArea.EditPanel,..UrlFromUI="Edit/MyStuff/MyPlugin.ascx"] Your custom VPP then checks for anything below /UI/Edit/MyStuff.
  6. Allan, that would be sweet! Perhaps a way to "register" a vpp-path with the resource-assembly/name.
  7. Now if only we could load a lang-file from the resources dynamically.
  8. Frerik: I have some sample code to load languagefiles dynamically from resources as well. Drop me an email (johan . olofsson (at) episerver . com ) and I'll be happy to send it to you.
  9. Got the source for this?
Post a comment    
User verification Image for user verification  
Allan Thræn

About me

I am a product manager @ EPiServer, with a passion for the more geeky side of things. My technical interests are typically focused around user problems, user experience,  search, information management, artificial intelligence and  personalization

On top of this blog I have the blog Allan On Technology and I often crosspost.

DISCLAIMER: Unless otherwise stated in the posts, this blog expresses my personal opinions, experiments and views, not necessarilly the views of EPiServer AB.

 443 page views this week.

 

 

Syndications


Archive


Tag cloud

EPiTrace logger