https://discord.umbraco.com logo
#package-development
Title
# package-development
w

warrenbuckley

07/20/2022, 2:13 PM
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 & @kevinjump or any others
k

kevinjump

07/20/2022, 2:14 PM
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

warrenbuckley

07/20/2022, 2:15 PM
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

kevinjump

07/20/2022, 2:16 PM
😦 - do you have the targets browser line still in your csproj file ? you can remove that
w

warrenbuckley

07/20/2022, 2:16 PM
I just saw in CMS we done it as a seperate class libary/project and its own Nuget package. Hence the original question
k

kevinjump

07/20/2022, 2:17 PM
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

warrenbuckley

07/20/2022, 2:17 PM
RE browser targets in csproj - nope
k

kevinjump

07/20/2022, 2:18 PM
😦 - 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

warrenbuckley

07/20/2022, 2:19 PM
This is the CSProj I have in helping Shan port Articulate
So no idea what I have done wrong/different :S
k

kevinjump

07/20/2022, 2:22 PM
I think its actually when its compiling the razor views. https://github.com/toddams/RazorLight/issues/236
w

warrenbuckley

07/20/2022, 2:25 PM
Hmmmm 🤔
Do I need a Nuget reference to
Microsoft.AspNetCore.Components.Web
k

kevinjump

07/20/2022, 2:36 PM
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

warrenbuckley

07/20/2022, 2:38 PM
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

kevinjump

07/20/2022, 2:43 PM
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

Jason

07/20/2022, 2:44 PM
I would add a
_viewImports.cshtml
in
~/views/
w

warrenbuckley

07/20/2022, 2:44 PM
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

Jason

07/20/2022, 2:45 PM
IIRC
_viewImports.cshtml
inside RCLs get munged into the main one
k

kevinjump

07/20/2022, 2:45 PM
are you refrencing Umbraco.Cms.Web.Common ? or Umbraco.Cms.Web.Website as they have smidge in them anyway ?
w

warrenbuckley

07/20/2022, 2:46 PM
Hmm it references Umbraco.Cms.Web.Backoffice & Umbraco.Cms.Web.Website in this project
k

kevinjump

07/20/2022, 2:47 PM
yeah so you should already have smidge
w

warrenbuckley

07/20/2022, 2:47 PM
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

Jason

07/20/2022, 2:54 PM
No worries, give me a ping tomorrow if you want another pair of eyes on it.
w

warrenbuckley

07/20/2022, 2:55 PM
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
@kevinjump 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

kevinjump

07/21/2022, 10:30 AM
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

warrenbuckley

07/21/2022, 10:39 AM
OK thanks will take a look after umbraCollab
k

kevinjump

07/21/2022, 10:42 AM
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

warrenbuckley

07/21/2022, 2:59 PM
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 @kevinjump ??
k

kevinjump

07/21/2022, 3:00 PM
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

warrenbuckley

07/21/2022, 3:01 PM
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

kevinjump

07/21/2022, 3:05 PM
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

Jason

07/21/2022, 3:08 PM
I would ditch app_plugins altogether
Just use /Articulate
w

warrenbuckley

07/21/2022, 3:10 PM
j

Jason

07/21/2022, 3:10 PM
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

warrenbuckley

07/21/2022, 3:12 PM
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

Jason

07/21/2022, 3:14 PM
I guess because it's "safe"
w

warrenbuckley

07/21/2022, 3:15 PM
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

Jason

07/21/2022, 3:16 PM
What do you mean?
w

warrenbuckley

07/21/2022, 3:19 PM
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

Jason

07/21/2022, 3:19 PM
Oh, yeah, no, that's what I mean about splitting them up.
w

warrenbuckley

07/21/2022, 3:20 PM
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

Jason

07/21/2022, 3:21 PM
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

warrenbuckley

07/21/2022, 3:25 PM
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

Jason

07/21/2022, 3:27 PM
I see
w

warrenbuckley

07/21/2022, 3:30 PM
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

Jason

07/21/2022, 3:30 PM
Yeah
That's not too much of a problem
w

warrenbuckley

07/21/2022, 3:31 PM
Yeh I just need to figure out what best to do really...
j

Jason

07/21/2022, 3:33 PM
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

warrenbuckley

07/21/2022, 3:34 PM
OK think I am following along....
j

Jason

07/21/2022, 3:37 PM
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

warrenbuckley

07/21/2022, 3:41 PM
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

Jason

07/21/2022, 3:50 PM
If you want a super-simple example of an RCL in action my repo still exists
w

warrenbuckley

07/21/2022, 3:58 PM
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 !