DEV Community

Kevin Jump
Kevin Jump

Posted on

Put your package in the installed package list in Umbraco 9

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 ?

Image description

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. 
    }
}
Enter fullscreen mode Exit fullscreen mode

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)

Collapse
 
leekelleher profile image
Lee Kelleher

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 and MigrationBase. Do you think I need to update this to use PackageMigrationPlan and PackageMigrationBase? 🤔

Collapse
 
skttl profile image
Søren Kottal

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?

Collapse
 
kevinjump profile image
Kevin Jump

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.