Anyone who's currently using an RCL for their pack...
# package-development
r
Anyone who's currently using an RCL for their package - I need to make some sort of hybrid between RCL and a normal NuGet package where I want my static assets to be installed with the RCL, but I need users to be able to see a single custom view within
App_Plugins/Umbraco.Community.BlockPreview/views/
. I can't figure out how to get the best of both worlds here as I'd need something like a targets file that only copies one file, is that right? Or does this defeat the purpose of an RCL?
r
Is it an Angular HTML or Razor CSHTML view? Both will be shipped in the RCL, but the Angular one will be exposed via the
WebRootFileProvider
and the Razor one will be compiled (so the source file won't be included). Also: Razor views can be overwritten by adding your own source code in the same place, but static assets like HTML will cause duplicate errors when building/publishing...
For Umbraco Forms we ship precompiled Razor views and provide the source files (for customization) as separate ZIP downloads in the documentation.
m
Its a cshtml file that needs to be selectable by the block grid preview file picker
r
Yeah, html file that I want to be selectable in the block grid “custom view” field
r
Hmm, seems to be a limitation of the file picker dialog that uses the
IPhysicalFileSystem
and not the
WebRootFileProvider
to get all files (probably because some file pickers also allow uploading new files and
IFileProvider
is read-only)... So that means it only shows actual physical files on disk. That essentially means you still need to copy over the file using the MSBuild target, although you can ship the rest of the files inside the RCL. So you indeed have to create a hybrid that uses a customized build target from https://github.com/umbraco/Umbraco-CMS/tree/contrib/templates/UmbracoPackage and the project setup from https://github.com/umbraco/Umbraco-CMS/tree/contrib/templates/UmbracoPackageRcl 🙃
d
There is another way
You can add an notification handler on the tree renderer notification and simply add your file to the root of the tree dialog
That's what I did with my block preview html view inside my razor class library:
Copy code
csharp
public class BlockPreviewTreeRenderingNotification : INotificationHandler<TreeNodesRenderingNotification>
{
    public void Handle(TreeNodesRenderingNotification notification)
    {
        if (!string.Equals(notification.TreeAlias, "staticFiles", StringComparison.Ordinal)
            || !string.Equals(notification.Id, Constants.System.RootString, StringComparison.Ordinal)) return;

        notification.Nodes.Add(new TreeNode("App_Plugins%2fblockpreview%2fblock-preview.html", null, null, null)
        {
            HasChildren = false,
            Icon = "icon-document",
            Name = "block-preview.html",
            ParentId = "-1",
        });
    }
}
It's important here that the
Name
property ends with
.html
.
r
Oh that is excellent @D_Inventor!
m
Sneaky until @Ronald Barendse updates the picker to use the WebRoot provider 😄
3 Views