1

Our solution, where after compiling locally, copies the views from the standard /view folder in the build output into a /client/views folder on in the web root. We're looking to take advantage of the RazorGenerator precompiled views and OOTB features mentioned by Kam in this blog post.

https://kamsar.net/index.php/2016/09/Precompiled-Views-with-Sitecore-8-2/

Assumption is that Sitecore uses the AssemblyIdentity collection below to pull a list of assemblies and loop thru trying to find a match based on the view renderings path listed on the Sitecore item.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <mvc>
      <precompilation>
        <assemblies>
          <assemblyIdentity name="My.Project" />
          <assemblyIdentity name="My.OtherProject" />
        </assemblies>
      </precompilation>
    </mvc>
  </sitecore>
</configuration>

Can anybody confirm this is how Sitecore does this match?

Does anybody have any experience overriding the RazorGenerator.MSBuild to build a custom path for the PageVirtualPath decorated attribute?

Current:
[PageVirtualPath("~/Views/Feature/Renderings/Sample.cshtml")]

Desired:
[PageVirtualPath("~/Client/Views/Feature/Renderings/Sample.cshtml")]

Or have other suggestions on how this works?

Update: Ticket into Sitecore support for clarification, but in meantime ran a test by:

  1. removing our route modification override
  2. updated all view renderings by quick yml unicorn sync to set default path
  3. deleted our custom view folder to verify they were getting pulled from assembly

That indeed worked and points to the PageVirtualPath as the mapping mechanism.

Guessing best route now is to pull RazorGenerator code down and modify to take in some additional build config properties to overwrite the base path when compilation is done.

3
  • I don't have a real answer, but enable debug logging and check for lines that start with PrecompiledViewAssembly, that should tell you if it's locating precompiled views in your assemblies. The logic is in the root of Sitecore.Mvc if you decompile it. – Matthew FitzGerald-Chamberlain Nov 9 '18 at 21:27
  • Thanks for the suggestion. I'll get to diggin' into the Sitecore assemblies to see and let you know what I find. – Steve Montgomery Nov 9 '18 at 23:23
  • I assume that you're updating the ViewLocationFormats of the razor engine? If so, I would expect that it would just work as expected – Matthew FitzGerald-Chamberlain Nov 9 '18 at 23:25
1

Was hoping for something more elegant but this seems to work. Adding a simple directive at the top of each razor view does the trick.

@*
VirtualPath: ~/Client/Views/Feature/Renderings/Sample.cshtml 
*@

Some quick settings

<setting name="Mvc.RenderersViewFolder">
        <patch:attribute name="value" value="/Client/Views/{1}/Renderings" />
  </setting>
  <setting name="Mvc.UsePhysicalViewsIfNewer">
    <patch:attribute name="value" value="true" role:require="Standalone" />
    <patch:attribute name="value" value="false" role:require="ContentManagement or ContentDelivery" />
  </setting>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.