In Umbraco v8 if you installed your package via the package manager it would appear in the list of installed packages in the packages dashboard.
in v9 all packages are installed via nuget. but wait some packages still appear in the installed package list ?
how do they do that ?
well the short answer is package migrations.
Package Migration
if your package has a package migration it will appear in the list. So even if you don't have anything you need to do in a migration you can put a blank one in to get into the list
uSync's basic package migration
public class uSyncMigrationPlan : PackageMigrationPlan
{
public uSyncMigrationPlan() :
base(uSync.PackageName)
{ }
protected override void DefinePlan()
{
To<SetupuSync>(new Guid("dd231cf5-5560-4f42-85a0-0ff8d8f37eb3"));
}
}
public class SetupuSync : PackageMigrationBase
{
public SetupuSync(
IPackagingService packagingService,
IMediaService mediaService,
MediaFileManager mediaFileManager,
MediaUrlGeneratorCollection mediaUrlGenerators,
IShortStringHelper shortStringHelper,
IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
IMigrationContext context)
: base(packagingService, mediaService, mediaFileManager, mediaUrlGenerators, shortStringHelper, contentTypeBaseServiceProvider, context)
{
}
protected override void Migrate()
{
// we don't actually need to do anything, but this means we end up
// on the list of installed packages.
}
}
here you just need a unique GUid value for your package
and a package name (uSync already had the name in a constant uSync.PackageName)
That's it
you don't need to register your package migration, it is auto discovered by Umbraco and the name will mean your package will appear in the backoffice
Top comments (3)
Thanks for the info Kevin.
You should have seen the lengths I went to make this work for NuGet installs of Contentment for Umbraco v8, e.g. github.com/leekelleher/umbraco-con...
For Umbraco v9, I still have the migration code in place, but I inherit from
MigrationPlan
andMigrationBase
. Do you think I need to update this to usePackageMigrationPlan
andPackageMigrationBase
? 🤔What happens if you remove the package? I guess it will still keep track of the initial migration, and keep saying that the package is installed?
I think this is actually done at runtime, so Umbraco is looking for classes of type
PackageMigrationPlan
so when your package is removed it also goes from the list.