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.
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?
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?
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)
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
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.
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
}
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.
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.
for uSync.Complete (which needs key and secret too) we do the following
First time visit to the dashboard, if the values are not set - user gets a dialog prompt.
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
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..
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.
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...
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.
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.
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.
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.
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?
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.
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
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 theapp_plugins
files from your package into the users web site when they install your packageYou can then use the dotnet pack command to make the package project e.g.
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
2) Create the package project from a template
3) create an umbraco site to test the package (-p is the package name)
now if you build the site / package you can test it on the test site.
4) to get a nuget package
that will go by default into bin/debug so to compile a release in a folder your want. (with a version)
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).
that is command lineish for create new empty project and add the two projects to it.
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?
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
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
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.
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
hen in a composer you load the options.
and then in your service/controller you can inject them into the constructor
then in appsettings.json you would have
Thanks again Kevin!
O.
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
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.
Hi,
for uSync.Complete (which needs key and secret too) we do the following
appsettings.json
filethis 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..
Thanks again Kevin. So copy/paste is the way forward rather than trying to get the package to do it somehow.
O.
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.
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...
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:
Any ideas where I might be going wrong with this?
Thanks in advance.
Alex
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.
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
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:
Do note though I have to remove them and re add the project references to be able to debug locally.
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
is working on a reply...