Using VirtualPathVersioningProvider in precompiled website
Versioning file system in EPiServer 5 is handled by VirtualPathVersioningProvider which is the default provider in EPiServer 5. Recently I had to resolve an issue with not registering the provider in precompiled website. There is a workaround here, but Coşkun's article shows how to register your custom provider, which probably won't require initialized EPiServer ClassFactory like the versioning provider. In my company we use such provider for some projects and this workaround works great. However, if you try to register EPiServer's versioning provider it will throw "ClassFactory not initialized" exception. This happens because somewhere deep in the constructor initialization logic of the provider there is a call to EPiServer.BaseLibrary.Context which requires Classfactory. Ted Nyberg wrote an improved version of Coşkun's fix but again he is using VirtualPathUnifiedProvider and not the Versioning provider.
If you examine EPiServer's global asax in reflector you will see that there is a call to SetupBaseLibrary (used for initialization of ClassFactory) which has to be called before InitializeVirtualPathProviders. Where these method are called depends on the EPiServer version for example in EPiServer CMS 5 SP2 they are located in Global class contructor. In the next service pack 3 - they called on the first request to the website:
Inside this StaticInitialization method there are calls to SetupBaseLibrary() and InitializeVirtualPathProviders().
This means that registering the Versioninng provider will work if it is called after SetupBaseLibrary()
In SP2 this is right in Application_Start method in Global.asax file. Here is the Ted's example modified to use Versioning provider:
I've changed the first line to check if the current provider is not VersioningProvider, because using if(VirtualPathHandler.PageFolderProvider == null) will always fail. This is because Application_Start event is fired after EPiServer's InitializeVirtualPathProviders() so PageFolderProvider is not null.
In Service pack 3 the InitializeVirtualPathProvider is called on first request so global.asax has to be changed a little:
In CMS 5 R2 SP2 version this provider initialization logic is moved to EPiServer.Web.InitializationModule class. One options is to put InitializeVersioningProvider in to a separate module and assure it is called after the EPiServer module. However I've didn't try this scenario.