Ok, I think I have an idea to solve my own question.
But it raises a new question.
The simplest way would be to query the ContentTypeService and parse all properties on the found contentTypes.
However I would want to try and create a T4 file with all my aliases printed. How can I use create an ApplicationContext in a T4 file snippet?
Or if that's not possible, how would one do this inside a console application?
To get the interface you can just create a new instance of the `ContentTypeService` class as well as new-ing up all of the dependencies which it takes into itself. But be aware that if you're doing this without the Umbraco WebApp things get nasty quickly as a internally Umbraco services use a mix of constructor-provided dependencies and `ApplicationContext` provided dependencies. In the narrow use-case of getting content types + their aliases you _should_ be fine to not setup `ApplicationContext`. You'll probably need to ensure your connection string is in the `*.config` used by the console application as Umbraco expects it to exist (and I had problems injecting it), as for T4 I have no idea how you create a "`*.config`" file.
Thanks for the quick response.
The config files are a pain indeed, getting errors like
Could not load the Umbraco.Core.Configuration.UmbracoSettings.IUmbracoSettingsSection from config file, ensure the web.config and umbracoSettings.config files are formatted correctly
at Umbraco.Core.Configuration.UmbracoConfig.UmbracoSettings()
Which makes sense though.
Maybe I should just create an ApiController that fills in the template at runtime.
Do you have the full stack-trace? I hit the problem with not being able to load the settings section but in the end I didn't need to use it be skipping around the dependencies.
Hey, you could always just write a Chauffeur Deliverable to do it ;)
Get a list of all the aliases
Hello,
I would like to obtain a list of all the ContentType aliases and the propertyAliases on those ContentTypes. What would be the easiest way to get this?
I'm not afraid to query the database myself. However it would be nice to have a solution that works without database specifics.
Ok, I think I have an idea to solve my own question.
But it raises a new question.
The simplest way would be to query the ContentTypeService and parse all properties on the found contentTypes. However I would want to try and create a T4 file with all my aliases printed. How can I use create an ApplicationContext in a T4 file snippet?
Or if that's not possible, how would one do this inside a console application?
You shouldn't need the `ApplicationContext`, if you're running outside of the Umbraco WebApp (which T4 would be).
My deployment tool Chauffeur just uses the services directly - https://github.com/aaronpowell/Chauffeur/blob/master/Chauffeur/Deliverables/ContentTypeDeliverable.cs#L30
To get the interface you can just create a new instance of the `ContentTypeService` class as well as new-ing up all of the dependencies which it takes into itself. But be aware that if you're doing this without the Umbraco WebApp things get nasty quickly as a internally Umbraco services use a mix of constructor-provided dependencies and `ApplicationContext` provided dependencies. In the narrow use-case of getting content types + their aliases you _should_ be fine to not setup `ApplicationContext`. You'll probably need to ensure your connection string is in the `*.config` used by the console application as Umbraco expects it to exist (and I had problems injecting it), as for T4 I have no idea how you create a "`*.config`" file.
Chauffeur now uses an IoC container to resolve dependencies so I don't really know what the dependency chain is any more, but looking at the earlier implementation (pre-IoC) you'll find https://github.com/aaronpowell/Chauffeur/blob/fbdc2c897bc3264a5f849f6ed74ba8ae8721f77f/Chauffeur/Deliverables/ContentTypeDeliverable.cs#L152-L216 which just bootstraps all the services itself.
Thanks for the quick response. The config files are a pain indeed, getting errors like
Could not load the Umbraco.Core.Configuration.UmbracoSettings.IUmbracoSettingsSection from config file, ensure the web.config and umbracoSettings.config files are formatted correctly at Umbraco.Core.Configuration.UmbracoConfig.UmbracoSettings()
Which makes sense though. Maybe I should just create an ApiController that fills in the template at runtime.
Do you have the full stack-trace? I hit the problem with not being able to load the settings section but in the end I didn't need to use it be skipping around the dependencies.
Hey, you could always just write a Chauffeur
Deliverable
to do it ;)Hmm, this should actually already work with the existing Deliverables I think.
umbraco> content-type get <id or alias>
gives everything back that I need, so it's matter of string parsing then.I'll try it out some time and let you know how it goes.
What am I missing here?
Probably, no idea what it'd be though, Chauffeur isn't designed to be used like that so I've got no idea how it would react.
is working on a reply...