Package development defaults and good practice #132
-
Moving to Umbraco 9 and .dotnet core changes the behaviors of somethings and moves things around. For package devs this leads to questions such as ‘where should this go’, and what is the best thing to do when adding X to a site. Umbraco and .Net are highly flexible when it comes to this, so you can put things almost anywhere, but for the sanity of Developers and users of Umbraco it might make sense to have some ‘conventions’ as to what to do. This purpose of this discussion is act as a place where we can gather some default suggestions, and maybe formulate some 'best practices' that could then make their way to the Umbraco docs as a guide page. All of the below are suggested starting points not recommendations (yet) App_PluginsFiles in Also the default target file behavior cleaning a build will remove the all the package files in App_Plugins so this will wipe all of a users changes? files that change/can be changed after a package is installed should be put in another location. ViewsIf a package contains views, then traditionally these would be added to the packages Package views exampleUmbraco forms, stores its views in Maybe views should be split out of app_plugins and live in the views folder if the intention is users can alter them after the package has been installed ? question is how do you deal with updates / upgrades - package dev would need to ensure these files are only overwritten the first time License filesUmbraco products store their licenses in The default Note :
|
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 13 replies
-
Also Settingspackages should not write to Possible options ??
* in theory there is a way to add your own config file into the appsettings config chain, but currently this might not be possible without altering the |
Beta Was this translation helpful? Give feedback.
-
I've only consumed, not created so far, but don't Razor Class Libraries effectively solve the problems mentioned with the App_Plugins and Views approaches? |
Beta Was this translation helpful? Give feedback.
-
I've been fiddling with my On rebuild, I'm now only copying files where the corresponding local copy hasn't been modified. To do that, I've added a task to my <UsingTask
TaskName="FindUnmodifiedEmailTemplates"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
<ParameterGroup>
<SourcePath ParameterType="System.String" Required="true" />
<TargetPath ParameterType="System.String" Required="true" />
<FilesToCopy ParameterType="System.String[]" Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.IO" />
<Using Namespace="System.Linq" />
<Code Type="Fragment" Language="cs">
<![CDATA[
var targetInfo = new DirectoryInfo(TargetPath);
var sourceInfo = new DirectoryInfo(SourcePath);
if (targetInfo.Exists && sourceInfo.Exists) {
var targetFiles = targetInfo.GetFiles();
var sourceFiles = sourceInfo.GetFiles();
var modifiedLocal = targetFiles.Where(file => file.LastWriteTime > file.CreationTime).Select(file => file.Name).ToArray();
FilesToCopy = sourceFiles.Where(file => !modifiedLocal.Contains(file.Name)).Select(file => file.FullName).ToArray();
}
]]>
</Code>
</Task>
</UsingTask> Then call the task: <FindUnmodifiedEmailTemplates SourcePath="$(MSBuildThisFileDirectory)..\Content\Views\Partials\WorkflowEmails"
TargetPath="$(MSBuildProjectDirectory)\Views\Partials\WorkflowEmails">
<Output TaskParameter="FilesToCopy" ItemName="ViewsToCopy" />
</FindUnmodifiedEmailTemplates> The output is the array of non-modified filepaths, which can then be copied: <Copy
SourceFiles="@(ViewsToCopy)"
DestinationFolder="$(MSBuildProjectDirectory)\Views\Partials\WorkflowEmails"
SkipUnchangedFiles="true" /> Is it perfect? Hells no, but it works (and needs some clean up). I'm doing similar in clean, but the custom task outputs an array of file paths representing the unmodified views. So far, it seems like this will let me put views anywhere, since I can be pretty specific about which folder to touch during clean/rebuild As for files in app_plugins, currently I'm planning on deleting |
Beta Was this translation helpful? Give feedback.
-
Spent some time (more than I intended) hacking on a proof of concept for an RCL with razor view and static file overriding downstream. It's definitely not as smooth as it could be, but with a bit of work on a custom task I think we could make things easier. https://github.com/p-m-j/umbraco_plugin_rcl_poc |
Beta Was this translation helpful? Give feedback.
-
I'm doing a package where I want the users to be able to add API-keys through the backoffice. Where should I save these? Is the umbracoKeyValue table suitable for this? I would prefer a solution, where I can have Deploy be able to pick up changes (even if I should write my own handler for that). Previously I have exploited dictionary keys for this, but that feels wrong 🙂 |
Beta Was this translation helpful? Give feedback.
-
Most (if not all) of these are now added to the documentation, see PRs umbraco/UmbracoDocs#3829 (original, closed) & umbraco/UmbracoDocs#5156 (updated, merged) and the final page on https://docs.umbraco.com/umbraco-cms/extending/packages/good-practice-and-defaults. |
Beta Was this translation helpful? Give feedback.
Most (if not all) of these are now added to the documentation, see PRs umbraco/UmbracoDocs#3829 (original, closed) & umbraco/UmbracoDocs#5156 (updated, merged) and the final page on https://docs.umbraco.com/umbraco-cms/extending/packages/good-practice-and-defaults.