*Package Gurus I am after some RCL advice* Do I ne...
# package-development
w
Package Gurus I am after some RCL advice Do I need to create a separate class library for just these static assets or can I modify the same class library that has my controllers, composers etc etc to do RCL stuff ?
Any pointers chuck them in this thread. Looking at you @Jason & @Kevin Jump or any others
k
Hi, you can do it all in the same class.
Change the SDK type on the csproj
Copy code
<Project Sdk="Microsoft.NET.Sdk.Razor">
w
Yep done that based on your notes/blog
But getting the following...
The document type '' does not support the extension 'ITemplateTargetExtension'.    Articulate    C:\Code\Articulate\src\Articulate\SDKRAZORGENERATE
k
😦 - do you have the targets browser line still in your csproj file ? you can remove that
w
I just saw in CMS we done it as a seperate class libary/project and its own Nuget package. Hence the original question
k
for uSync i do it as a seperate one, but only because other packages include the uSync core (e.g complete) and i didn't want the static files in those projects.
at the moment i am doing stuff in a single project when its not that.
w
RE browser targets in csproj - nope
k
😦 - at the moment have this for a thing i am doing ...
Copy code
`
<Project Sdk="Microsoft.NET.Sdk.Razor">

    <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <StaticWebAssetBasePath>App_Plugins</StaticWebAssetBasePath>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="uSync.BackOffice" Version="10.0.0" />
        <PackageReference Include="uSync.Expansions.Core" Version="10.0.0" />
    </ItemGroup>

</Project>
and that's it. (wwwroot is then app_plugins so my files are in
wwwroot/mypackage
)
w
This is the CSProj I have in helping Shan port Articulate
So no idea what I have done wrong/different :S
k
I think its actually when its compiling the razor views. https://github.com/toddams/RazorLight/issues/236
w
Hmmmm 🤔
Do I need a Nuget reference to
Microsoft.AspNetCore.Components.Web
k
You might if you are compiling razor views. ...
when i have razor views i've these additional lines :
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
in the top of the .proj file and
Copy code
<ItemGroup>
 <PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="6.0.4" />
</ItemGroup>
w
OK I know why
Like you say I need
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
As Articulate is shipping views not just CSS/JS/HTML views (Maybe worth mentioning in your blog series Kevin ?)
OK next problem as these views depend on Smidge (We assume the NuGet is there as transient dependency from Umbraco) But getting the following IHtmlHelper' does not contain a definition for 'RenderCssHere' and no accessible extension method 'RenderCssHere' accepting a first argument of type 'IHtmlHelper' could be found (are you missing a using directive or an assembly reference?) C:\Code\Articulate\src\Articulate\App_Plugins\Articulate\Views\MarkdownEditor.cshtml
k
I suspect in a web project the usings are in the _viewImports.cshtml file, and when you are in your own library that's not being used, so maybe you have to be explicit with the using values inside the razor views ?
j
I would add a
_viewImports.cshtml
in
~/views/
w
But if I do a nuget reference from this class library means I am having to tie myself to that version of Smidge and not the transient from Umbraco
OK off to try the _viewimports.chstml
j
IIRC
_viewImports.cshtml
inside RCLs get munged into the main one
k
are you refrencing Umbraco.Cms.Web.Common ? or Umbraco.Cms.Web.Website as they have smidge in them anyway ?
w
Hmm it references Umbraco.Cms.Web.Backoffice & Umbraco.Cms.Web.Website in this project
k
yeah so you should already have smidge
w
Yep exactly I do
But getting this bitching at me - gonna try the _viewimports.cshtml
God dammn it - ignore me Think I know the issue
End of day so gonna park this here - will let you know if its somethign stupid thats caught me out. Gut feeling is that the PR I am working in does not have the updated code for Smidge stuff 🙈 But the
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
was something I deffinitely needed. So thanks gang !!
j
No worries, give me a ping tomorrow if you want another pair of eyes on it.
w
Yeh cheers Jas, I might well do & may have a question how I can read these files in the RCL off disk in some kind of fileprovider thingy perhaps?! As Articulate is storing its frontend views/themes as opposed to the usual /views folder
@Kevin Jump looking at your PR if I want to query folders/files in the RCL that are not on disk. So I can't use System.IO to list out the directories for Themes for a Theme picker property editor. Am I right in understanding that I need to use the following? https://github.com/umbraco/Umbraco-CMS/pull/12206/files#diff-a5f249fdbafa209c33651a6ae9ed26a9ec65628f0119c492e2611ad032f00238R43-R44
Copy code
csharp
var webFileProvider = webHostEnvironment.WebRootFileProvider;
var contentFileProvider = webHostEnvironment.ContentRootFileProvider;
k
Yes , in a perfect world you only need the webFileProvider, but there is an oddity with Umbraco's static app_plugins files that means sometimes that folder isn't in the collection. https://github.com/umbraco/Umbraco-CMS/pull/12552
w
OK thanks will take a look after umbraCollab
k
Just thinking about it if you are reading files you probibly only need the WebFileProvider, because its just a caching issue in the Lang files that means that PR reads both
w
OK so with this
Copy code
csharp
var dirs = _webHostEnvironment.WebRootFileProvider.GetDirectoryContents("/App_Plugins/Articulate/Themes");
return dirs.Where(x=> x.IsDirectory).Select(x => x.Name);
It's listing out the directories in the folder in the RCL, but I was assuming that if I added a new folder on disk at
/App_Plugins/Articulate/Themes/Warren
which didn't exist it would have munged & merged it together with the WebRootFileProvider stuff @Kevin Jump ??
k
I think, it returns multiple '/App_Plugins/` at the root, so you have to enumerate through them to get to where you want to look.
w
Well the above code works and lists me the folders from the RCL at that location just fine
But if I add the physical folder on disk at the same folder location (which didnt exist) I was expected the list of folders to be merged with the ones from the RCL if that makes sense?!
k
Yeah i am not 100% sure, i think you have to ask for hte contents of App_plugins, and then you might find there are two Articulate folders returned - one for the RCL and one for the phyisical folder i am not sure.
I would also try this by adding the file to
wwwroot/app_plugins/Articulate/themes
see if that works. because app_plugins is an Umbraco static file thing wwwroot/app_plugins is the razor one, they might behave diffrently ?
j
I would ditch app_plugins altogether
Just use /Articulate
w
j
static assets in wwwroot in the RCL will automatically be moved to wwwroot/Articulate
Yeah, that logic wont work any more
You'll nee to split your static assets from your views
And join them up by path/naming convention
w
Ah yeh OK so it shows up in that folder if I add it inside wwwroot with App_Plugins
Yeh not sure why Shan served the Articulate Themes from inside the App_Plugins to begin with, probably some reason or workaround...
j
I guess because it's "safe"
w
OK will try dropping App_Plugins from the RCL stuff so to override it just becomes wwwroot/articulate/themes/
But not sure if that feels right either then physical file is in wwwroot then it can be served via the browser if you know the filepath/filename, which feels WONKY
j
What do you mean?
w
Well I could browse to
mysite.co.uk/articulate/themes/Material/Views/Post.cshtml
and the raw content of the view would be sent down the wire as everything in wwwroot considered static asset ?
j
Oh, yeah, no, that's what I mean about splitting them up.
w
Heres a screenshot of the folder structure that is in App_Plugins for Articulate currently (Mix of views/themes with CSS & JS for the frontend render AND the backoffice property editors etc)
j
So you'd have two separate places
wwwroot/Articulate/Themes/MyCoolTheme/main.css Articulate/Themes/MyCoolTheme/Page.cshtml
Also, for the static assets you'll get a prefix, so it will actually be: wwwroot/_{package name}/Articulate/Themes/MyCoolTheme/main.css
w
Still not sure I how split it into two?
When I can only set one RCL base path?!
My afternoon brain is clearly NOT getting this
j
I see
w
And Shan's Articulate Controllers basically return the paths to the Views in the App_Plugins (Nothing in the templates/views in the normal place for Umbraco)
return View(PathHelper.GetThemeViewPath(author, "Author"), author);
j
Yeah
That's not too much of a problem
w
Yeh I just need to figure out what best to do really...
j
So, in an RCL, the views get compiled. So they're not actually shipped. They're referenced based on where they lived in the RCL project. Usually something like
/views/whatever/whatever.cshtml
It doesn't really matter what the folder structure is.
w
OK think I am following along....
j
Static assets are best just dropped in wwwroot. It's not the only option, but it works , is predictable, and you don't have to fight the framework
I didn't bother setting StaticWebAssetBasePath, because the RCL will automatically make wwwroot work anyway.
> When the app is published, the companion assets from all referenced projects and packages are copied into the wwwroot folder of the published app under _content/{PACKAGE ID}/
The thing we learnt yesterday from @Craig100 is that using app_plugins in RCLs can actually lead to confusion. For us package devs we're used to it being "the place you put stuff". But that' snot actually where things are going in an RCL and it will behave very differently for people consuming the package. i.e. using the same name for a very different thing.
w
Yeh think its causing me confussion/headaches for sure !!
Right I need to wrap up for the day and tackle this tomorrow. I may ping you for a chat/call if thats OK Jas - may be easier/quicker if I am still stuck
j
If you want a super-simple example of an RCL in action my repo still exists
w
Yep got kid and wife shouting at me as work day is over. So will look later on tonight or tomorrow at yours Jas. thanks again !
6 Views