Search code examples
asp.netasp.net-mvcvirtualpathprovider

How to be able to select master pages that are provided by a VirtualPathProvider


We got a lot of intranet websites that share the same design. Therefore we've put the master pages, stylesheet, images and javascripts in a shared assembly.

The content is loaded by using:

HostingEnvironment.RegisterVirtualPathProvider(new VirtualFilesProvider());
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new WebFormViewEngineWithOurVirtualPathProvider());

The problem is that Visual Studio cannot find the images or masterpage and therefore gives us a lot of warnings + that we cannot select the masterpage when creating new view pages.

Can that be fixed in any way?

Note: Everything works fine when running the websites.


Solution

  • If VisualStudio cannot find the physical file then it will show warnings. There is really no solution to this.

    An alternative approach is to use a post build / pre deploy script to copy shared files between projects. An added benefit is a faster site, a embedded resource virtual path provider is slow.