baseVirtualPath doesnt apply to location formats.

Sep 3, 2014 at 2:22 PM

I have a solution where our vendors upload compiled RazorGenerator views to a /Custom/
folder on our webserver. Now, the baseVirtualPath allows me to prevent clashing between the vendors views and our own views:
if (assembly.GetTypes().Any(t => typeof (WebPageRenderingBase).IsAssignableFrom(t)))
    var engine = new PrecompiledMvcEngine(assembly, "~/Custom/");
    ViewEngines.Engines.Insert(0, engine);
However, the baseVirtualPath is not added to the location formats the VirtualPathFactoryManager can't find the views - however it should be easy to fix, example:
base.ViewLocationFormats = new[] {
    CombineVirtualPaths(_baseVirtualPath, "~/Views/{1}/{0}.cshtml"), 
    CombineVirtualPaths(_baseVirtualPath, "~/Views/Shared/{0}.cshtml"), 
Sep 3, 2014 at 5:57 PM
If you get a fix going, please send a PR and we'll get it in. Thanks!
Sep 30, 2014 at 10:28 AM

In fact I have another idea about making 'CombineVirtualPaths' more flexible.
I prefer to add another constructor which is included a Func parameter:
public PrecompiledMvcEngine(Assembly assembly)
            : this(assembly, null)

        public PrecompiledMvcEngine(Assembly assembly, string baseVirtualPath)
            : this(assembly, baseVirtualPath, null)

        public PrecompiledMvcEngine(Assembly assembly, string baseVirtualPath, Func<String, String, String> CustomCombineVirtualPaths)
            : this(assembly, baseVirtualPath, CustomCombineVirtualPaths, null)

public PrecompiledMvcEngine(Assembly assembly, string baseVirtualPath, Func<String, String, String> CustomCombineVirtualPaths, IViewPageActivator viewPageActivator)
            _assemblyLastWriteTime = new Lazy<DateTime>(() => assembly.GetLastWriteTimeUtc(fallback: DateTime.MaxValue));

            if (CustomCombineVirtualPaths == null)
                _baseVirtualPath = NormalizeBaseVirtualPath(baseVirtualPath);
                CustomCombineVirtualPaths = CombineVirtualPaths;
                _baseVirtualPath = baseVirtualPath;


            _mappings = (from type in assembly.GetTypes()
                         where typeof(WebPageRenderingBase).IsAssignableFrom(type)
                         let pageVirtualPath = type.GetCustomAttributes(inherit: false).OfType<PageVirtualPathAttribute>().FirstOrDefault()
                         where pageVirtualPath != null
                         select new KeyValuePair<string, Type>(CustomCombineVirtualPaths(_baseVirtualPath, pageVirtualPath.VirtualPath), type)
                         ).ToDictionary(t => t.Key, t => t.Value, StringComparer.OrdinalIgnoreCase);
            this.ViewLocationCache = new PrecompiledViewLocationCache(assembly.FullName, this.ViewLocationCache);
            _viewPageActivator = viewPageActivator 
                ?? DependencyResolver.Current.GetService<IViewPageActivator>() /* For compatibility, remove this line within next version */
                ?? DefaultViewPageActivator.Current;
and the Custom function, for example can be like this:
private static string CustomCombineVirtualPaths(string baseVirtualPath, string virtualPath)
            if (!String.IsNullOrEmpty(baseVirtualPath))
                return virtualPath.Replace("~/", baseVirtualPath);
            return virtualPath;
Thank you so much...