EPiServer and the Visual Web Developer 2008.
I've heard the question "Can we use the Web Site model of Visual Studio to build our EPiServer solution" a couple of times and up until now the answer to this question have been "No!". The reason for this is that there is no way to exclude files and folders like the UI and Util folder from being "treated" by Visual Studio in this model without excluding them from the site entirely.
However, ASP.NET 2.0 introduced a feature called Virtual Path Providers that EPiServer use and extend a bit in EPiServer CMS 5. This feature makes it possible to "plugin" virtual file systems on configurable locations in the application. The main reason for using this in EPiServer is for exposing file systems to the filemanager but it turns out that there are other situations where these VPP's come in handy. For instance, it makes it possible to hide EPiServer application folders (UI, Util, WebSerices) for Visual Studio but still exposing them to the ASP.NET site... and that is basically what we need to support the Web Site model.
Setting up the project
Here's what you do:
- Create a EPiServer CMS 5 SP1 project from Visual Studio 2005.
- Close Visual Studio.
...Now, to be brave and make things a little more interesting, I am going to show the steps for doing this in Visual Studio 2008 (and if your'e both cheap and brave try Visual Web Developer 2008 Express Edition)...
- So, open the flavour of Visual Studio that suites you. Note for Vista users: I have to run VS as administrator (right click the VS icon and select Run as administrator) to be able to debug this site for some reason that I haven't been able to crack yet.
- Select "Open Web Site..." and locate the project directory you just created.
- Visual Studio 2008 has this wonderful new feature called "multi targeting" which lets you choose which version of the framework that you want to use for you project... So, when you open the folder as a web site Visual Studio will prompt you with the following question:
- Choose "Yes"...we have already decided to be brave right?... and besides, what could possibly go wrong?!
- Select the project root in the solution explorer and pull up its properties (F4)
- Set "Use dynamic ports" to False.
- Set the port number to whatever port number is used in the web.config. (default 6666)
- Now get rid of the csproj and csproj.user file from the solution explorer.
- Move the application folders (UI, Util and WebServices) to a location outside the application directory. For this example i used a directory in the user directory that I called ApplicationFiles.
- Add a VirtualPathNativeProvider configuration for each relocated folder in Web.config. Set the physicalPath attribute to wherever your UI, Util and WebServices files are located.
<add
showInFileManager="false"
virtualName="UI"
virtualPath="~/UI/"
physicalPath="%USERPROFILE%\ApplicationFiles\5.1.422.122\UI"
name="UIFiles"
type="EPiServer.Web.Hosting.VirtualPathNativeProvider,EPiServer" />
<add
showInFileManager="false"
virtualName="Util"
virtualPath="~/Util/"
physicalPath="%USERPROFILE%\ApplicationFiles\5.1.422.122\Util"
name="UtilFiles"
type="EPiServer.Web.Hosting.VirtualPathNativeProvider,EPiServer" />
<add
showInFileManager="false"
virtualName="WebServices"
virtualPath="~/WebServices/"
physicalPath="%USERPROFILE%\ApplicationFiles\5.1.422.122\WebServices"
name="WebServiceFiles"
type="EPiServer.Web.Hosting.VirtualPathNativeProvider,EPiServer" />
We are now finished with setting up the site configuration to be used with the Visual Studio web site model. Using this model provides a number of features not available for the web application project that we normally use for EPiServer development such as "compile on the fly" type of development, support for Visual Basic.NET (
if you're more into reading your code than writing it) and even mixed language development. We have also seen that this is all possible using the Visual Studio 2008 product family.
Creating a page template
The next step for the site is ofcourse filling it with page templates, user controls and master pages. Unfortunately, the item templates for creating these items for EPiServer is not available in the web site model but here's what you do to add a for instance a page template for the start page.
Enjoy!
24 January 2008