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 481 posts 1413 karma points MVP 7x c-trib
    Feb 09, 2022 @ 21:54
    Owain Williams
    0

    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 2342 posts 14889 karma points MVP 8x c-trib
    Feb 10, 2022 @ 09:43
    Kevin Jump
    102

    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 481 posts 1413 karma points MVP 7x c-trib
    Feb 10, 2022 @ 15:06
    Owain Williams
    0

    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 2342 posts 14889 karma points MVP 8x c-trib
    Feb 10, 2022 @ 15:12
    Kevin Jump
    1

    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" />
    
    <ItemGroup>
        <ProjectReference Include="..\my.super.package\my.super.package.csproj" />
    </ItemGroup>
    

    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 481 posts 1413 karma points MVP 7x c-trib
    Feb 10, 2022 @ 16:19
    Owain Williams
    0

    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.

    O.

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Feb 10, 2022 @ 16:25
    Kevin Jump
    1

    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>()               
                        .Bind(builder.Config.GetSection("MyPackage"));
    

    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 481 posts 1413 karma points MVP 7x c-trib
    Feb 10, 2022 @ 16:54
    Owain Williams
    0

    Thanks again Kevin!

    O.

  • Owain Williams 481 posts 1413 karma points MVP 7x c-trib
    Feb 22, 2022 @ 21:58
    Owain Williams
    0

    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 2342 posts 14889 karma points MVP 8x c-trib
    Feb 22, 2022 @ 22:03
    Kevin Jump
    2

    Hi,

    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>
        <div>
            <umb-code-snippet language="'json'">{{model.result.json}}</umb-code-snippet>
        </div>
    
  • Owain Williams 481 posts 1413 karma points MVP 7x c-trib
    Feb 23, 2022 @ 09:04
    Owain Williams
    0

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

    O.

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Feb 23, 2022 @ 09:44
    Kevin Jump
    0

    Yeah,

    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.

  • Alex Solek 5 posts 78 karma points
    Feb 24, 2023 @ 23:28
    Alex Solek
    0

    Hi Kevin and Owain,

    Apologies if this should go in a separate thread, but I figured my question is related.

    I am trying to package up my own starter kit into an internal NuGet package, but I also have used the ConditionalDisplayers package to set up some of my data types on the starter kit. I am then using an XML package migration plan in the package which will import that into the new Umbraco site when it installs the NuGet package. Followed Paul Seal's example.

    I have followed the steps above from Kevin to set up a new NuGet package which works fine. I can pack the NuGet package, and in the terminal, I can see that the Conditional Displayers package files seem to be copied over...

    Copying ConditionalDisplayers files: 
     C:\Users\alex.solek\.nuget\packages\our.umbraco.conditionaldisplayers\3.2.1\buildTransitive\..\App_Plugi
          ns\ConditionalDisplayers\**\*.* - #9 files
    

    I then push the package up to my local feed and install on a new project and everything goes well until it reads my package.xml file to import all the data types, content types etc. And I keep hitting this error in the terminal and the site won't build. I have also installed the ConditionalDisplayers package directly on the new project, but get the same result:

    Could not find an editor with alias Our.Umbraco.CdCheckbox, treating as Label. The site may fail to boot and/or load data types and run.
    

    Any ideas where I might be going wrong with this?

    Thanks in advance.

    Alex

  • Owain Williams 481 posts 1413 karma points MVP 7x c-trib
    Feb 27, 2023 @ 09:40
    Owain Williams
    0

    Hi Alex, It looks like the ConditionalDisplayer package isn't installing first and so your package can't installed due to this dependency.

    I've not created a package that has another package as a dependency yet, but maybe someone else can help you with that.

    I'll reach out to others and see if anyone else can join this conversation and help.

    O.

  • Alex Solek 5 posts 78 karma points
    Feb 27, 2023 @ 10:34
    Alex Solek
    0

    Hi Owain,

    Thank you for your reply. I appreciate it.

    What's interesting is that I do have the required files in the App_Plugins directory on both the package project and the project that consumes the package, and I also have the ConditionalDisplayers.dll in my bin directory.

    I also used the NuGet package explorer and can see the ConditionalDisplayers folder with the App_Plugins directory as part of the NuGet package.

    I also found that when I manually modify the package.xml file and change the property types to say text string I can bypass this error, so I am not sure if this could be anything to do with the XML migration which may not be recognizing that property type as valid.

    Thanks again.

    Alex

  • Aaron 58 posts 406 karma points MVP 2x c-trib
    Feb 27, 2023 @ 10:42
    Aaron
    0

    I've done something similar with UmbNav.Web which relies on UmbNav.Core and UmbNav.Api.

    I have to add the following lines to the .Web project:

    <ItemGroup>
        <PackageReference Include="Our.Umbraco.UmbNav.Api" Version="2.0.2" />
        <PackageReference Include="Our.Umbraco.UmbNav.Core" Version="2.0.1" />
    </ItemGroup>
    

    Do note though I have to remove them and re add the project references to be able to debug locally.

  • Alex Solek 5 posts 78 karma points
    Feb 27, 2023 @ 15:49
    Alex Solek
    0

    Hi Aaron,

    Thanks for your response.

    I do have PackageReference to the ConditionalDisplayers package in the project I am packaging up as well as the site that uses the package. But unfortunately, I still get the same issue when installing the content using the XML migration method.

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft