Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Owain Williams 461 posts 1351 karma points MVP 5x c-trib
    Feb 09, 2022 @ 21:54
    Owain Williams

    Package creation questions

    Hi, I'm currently working on a content app which I hope you make in to a package soon but I've got some questions.

    1. I've got my content app files in appplugins but then I've also got c# files e.g controllers, models, dB migration files external to the appplugins folder. How would I package all this up so that it would work on someone else's install?

    2. The content app will need the user to have added an API key / API secret, how would you set this up in umbraco 9? Some sort of config file?

    Thanks, O.

  • Kevin Jump 2146 posts 13582 karma points MVP 6x c-trib
    Feb 10, 2022 @ 09:43
    Kevin Jump

    Hi Owain,

    if you have your app_plugins and c# files inside a current Umbraco site then the first thing you probably need to do is move them into their own project, so you can build just those files and package them into a nuget package.

    There is a template for packages included in the Umbraco templates, so you can create a package project with them

    dotnet new umbracopackage -n myUmbracoPackage 

    this will create the basic skeleton of a package you can use for your package,

    if you move your files into the app_plugins folder of this project and the c# files into folders in the root of the project (e.g controllers, models, etc) When you build this project it will compile the c# files down for you.

    This template contains the all important .targets file which actually does the copying of the app_plugins files from your package into the users web site when they install your package

    You can then use the dotnet pack command to make the package project e.g.

    dotnet pack .\ourumbracopackage.csproj 

    will generate the .nuget file.

    Step by step example:

    For a good setup to test you can also add your package to a new Umbraco site, again the templates let you do this.

    A set of steps you might follow to get a package and a website you can test the package one.

    1) Create a folder for your package

    mkdir MySuperPackage
    cd .\MySserPackage

    2) Create the package project from a template

    dotnet new umbracopackage -n my.super.package

    3) create an umbraco site to test the package (-p is the package name)

    dotnet new umbraco -n myTestSite -p my.super.package

    now if you build the site / package you can test it on the test site.

    4) to get a nuget package

    dotnet pack .\my.super.package.csproj 

    that will go by default into bin/debug so to compile a release in a folder your want. (with a version)

    dotnet pack .\my.super.package.csproj -c release -o ./output /p:version=1.0

    that command will build a release version of the package, sets its version to 1.0 and puts the package in a output folder

    bonus: if you want a .sln file (for visual studio).

    dotnet new sln
    dotnet sln add .\myTestSite\myTestSite.csproj
    dotnet sln add .\my.super.package\my.super.package.csproj

    that is command lineish for create new empty project and add the two projects to it.

  • Owain Williams 461 posts 1351 karma points MVP 5x c-trib
    Feb 10, 2022 @ 15:06
    Owain Williams

    Amazing! Thanks Kevin! That's really helpful.

    At step 3 - is there a way to add the package to an existing Umbraco setup rather than creating a new Umbraco instance?

  • Kevin Jump 2146 posts 13582 karma points MVP 6x c-trib
    Feb 10, 2022 @ 15:12
    Kevin Jump

    Hi Owain,

    yes - if you add the package as a reference to the existing project then that will copy the dll. in when it builds.

    you can then either add the targets file to the projects .csproj file (i think this is what the template does) e.g

    <Import Project="..\my.super.package\build\my.super.package.targets" />
        <ProjectReference Include="..\my.super.package\my.super.package.csproj" />

    but personally for app_plugins what i do (and its a little bit more setup, but faster working). is i have a gulp script that copies files from the packages appplugins folder to the sites appplugins folder

    (for example backofficethemes package has this gulpfile.js, and a paths.json file that tells it to copy files from a to b.)

    this just means when you are working with the html/js files you can just save them in the project and they are copied over, and you don't have to restart / rebuild the your site or package to see those changes

  • Owain Williams 461 posts 1351 karma points MVP 5x c-trib
    Feb 10, 2022 @ 16:19
    Owain Williams

    Perfect! That works. The csproj update approach. I'll look at the gulp option in future too though as it sounds really good.

    Final question - for now 😉

    How would you recommend setting up API keys from a user? So the user will need to get the API keys from the API and then save them in to the content app, somehow.


  • Kevin Jump 2146 posts 13582 karma points MVP 6x c-trib
    Feb 10, 2022 @ 16:25
    Kevin Jump

    Put them in appsettings.json

    While you could have all sorts of cool, DB , or other settings if you put them in the appsettings.json file, you hook into all the power of that in netcore, people can store them in key vaults, environmental variables etc..

    for this you need a model class which contains your AppId and AppKey

    public class MyPackageSettings {
           .... settings here

    hen in a composer you load the options.

    var options = builder.Services.AddOptions<MyPackageSettings>()               

    and then in your service/controller you can inject them into the constructor

    public myService(IOptions<MyPackageSettings> settings) {
        // read the model here

    then in appsettings.json you would have

    "MyPackage": {
         "AppId": "",
         "AppKey": ""
  • Owain Williams 461 posts 1351 karma points MVP 5x c-trib
    Feb 10, 2022 @ 16:54
    Owain Williams

    Thanks again Kevin!


  • Owain Williams 461 posts 1351 karma points MVP 5x c-trib
    Feb 22, 2022 @ 21:58
    Owain Williams

    Following up from the earlier question about adding API keys etc in appsettings.json - I have that working but I have a question about how the user would set this up after installing the package.

    So in appsettings.json I have

     "ocTweetThis": {
    "ConsumerKey": "NotRealConsumerKey",
    "ConsumerSecret": "NotRealConsumerSecret",
    "AccessToken": "NotRealAccessToken",
    "AccessSecret": "NotRealAccessSecret,
    "EnableLiveTweeting":  "True"  }

    Would they need to copy/paste this section in to the appsettings.json file via instructions with the package or is there a way to do this when the package is installed. The user would still need to enter in their API secrets etc but that's a bit less work.

  • Kevin Jump 2146 posts 13582 karma points MVP 6x c-trib
    Feb 22, 2022 @ 22:03
    Kevin Jump


    for uSync.Complete (which needs key and secret too) we do the following

    1. First time visit to the dashboard, if the values are not set - user gets a dialog prompt.

    enter image description here

    1. if they click generate the back end code generates the keys and presents the user with a dialog where they can copy the chunk of json to put into the appsettings.json file

    enter image description here

    this way they get to choose where to put it.

    edit: just to add the code box with a copy isn't anything fancy we have done, its part of the Umbraco core..

        <h4>appsettings.json config</h4>
            <umb-code-snippet language="'json'">{{model.result.json}}</umb-code-snippet>
  • Owain Williams 461 posts 1351 karma points MVP 5x c-trib
    Feb 23, 2022 @ 09:04
    Owain Williams

    Thanks again Kevin. So copy/paste is the way forward rather than trying to get the package to do it somehow.


  • Kevin Jump 2146 posts 13582 karma points MVP 6x c-trib
    Feb 23, 2022 @ 09:44
    Kevin Jump


    I think that's the best way, if you want the settings to be portable with the site (if you don't mind them not being your can stuff them in the DB).

    but just to be clear it is possible to write back to appsettings.json (isn't everything possible?)

    its just not a recommended thing because settings can be formed from so many locations, and the way dotnet core projects are built and then published means things could/will get overwritten when a site is redeployed.

Please Sign in or register to post replies

Write your reply to: