Copied to clipboard

Flag this post as spam?

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


  • Ben Palmer 180 posts 866 karma points c-trib
    Mar 29, 2017 @ 21:18
    Ben Palmer
    0

    Creating a Nuget Package with Document Types

    Hi,

    I've been attempting to set up a simple package for Umbraco which creates a few document types and data types. It also has a few classes to do a bit of heavy lifting.

    However, what I'd ideally like to do is create a Nuget package so that I can easily install and update the extension. I've managed to get a set up working for me that creates the Nuget package (along with a zip, and the actual Umbraco package itself). This appears to be working for my bin file - the dll is copied across and I can using the namespaces in my other test project.

    What I'm failing to understand however, is how to use the package.xml file that Umbraco creates in my Nuget package. I've created a package in my Umbraco installation and ticked the document types and data types that I want to export and it gives me the following XML file:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <umbPackage>
      <files />
      <info>
        <package>
          <name>Umbraco Rss Feeds</name>
          <version>0.0.0.4</version>
          <iconUrl />
          <license url="http://opensource.org/licenses/MIT">MIT License</license>
          <url>http://benpalmer.me</url>;
          <requirements type="strict">
            <major>7</major>
            <minor>5</minor>
            <patch>11</patch>
          </requirements>
        </package>
        <author>
          <name>Ben Palmer</name>
          <website>http://benpalmer.me</website>;
        </author>
        <readme><![CDATA[]]></readme>
      </info>
      <DocumentTypes>
        <DocumentType Folders="UmbracoRssFeeds">
          <Info>
            <Name>Rss Feed</Name>
            <Alias>umbracoRssFeed</Alias>
            <Icon>icon-rss</Icon>
            <Thumbnail>folder.png</Thumbnail>
            <Description />
            <AllowAtRoot>False</AllowAtRoot>
            <IsListView>False</IsListView>
            <Compositions />
            <AllowedTemplates>
              <Template>UmbracoRssFeed</Template>
            </AllowedTemplates>
            <DefaultTemplate>UmbracoRssFeed</DefaultTemplate>
          </Info>
          <Structure />
          <GenericProperties>
            <GenericProperty>
              <Name>Feed Content</Name>
              <Alias>parentNode</Alias>
              <Type>Umbraco.ContentPickerAlias</Type>
              <Definition>a6857c73-d6e9-480c-b6e6-f15f6ad11125</Definition>
              <Tab>Details</Tab>
              <SortOrder>0</SortOrder>
              <Mandatory>False</Mandatory>
              <Description><![CDATA[Choose which content node to start at.]]></Description>
            </GenericProperty>
            <GenericProperty>
              <Name>Allowed Document Types</Name>
              <Alias>allowedDocumentTypes</Alias>
              <Type>Umbraco.MultipleTextstring</Type>
              <Definition>62fd2622-3ce7-4e0d-9f2e-1b1dcdbaee85</Definition>
              <Tab>Details</Tab>
              <SortOrder>1</SortOrder>
              <Mandatory>False</Mandatory>
              <Description><![CDATA[Used to restrict what document types will be pulled through as content into the feed. If left empty, all document types will be allowed.]]></Description>
            </GenericProperty>
            <GenericProperty>
              <Name>Levels</Name>
              <Alias>levels</Alias>
              <Type>Umbraco.Integer</Type>
              <Definition>217583da-877e-44b6-9735-909960dba723</Definition>
              <Tab>Details</Tab>
              <SortOrder>2</SortOrder>
              <Mandatory>False</Mandatory>
              <Description><![CDATA[Specify the number of levels to look down for content. Set as 0 for unlimited.]]></Description>
            </GenericProperty>
          </GenericProperties>
          <Tabs>
            <Tab>
              <Id>14</Id>
              <Caption>Details</Caption>
              <SortOrder>0</SortOrder>
            </Tab>
          </Tabs>
        </DocumentType>
        <DocumentType Folders="UmbracoRssFeeds">
          <Info>
            <Name>Rss Feeds</Name>
            <Alias>umbracoRssFeeds</Alias>
            <Icon>icon-rss color-orange</Icon>
            <Thumbnail>folder.png</Thumbnail>
            <Description />
            <AllowAtRoot>False</AllowAtRoot>
            <IsListView>False</IsListView>
            <Compositions />
            <AllowedTemplates>
              <Template>UmbracoRssFeed</Template>
            </AllowedTemplates>
            <DefaultTemplate>UmbracoRssFeed</DefaultTemplate>
          </Info>
          <Structure>
            <DocumentType>umbracoRssFeed</DocumentType>
          </Structure>
          <GenericProperties>
            <GenericProperty>
              <Name>Description</Name>
              <Alias>feedsDescription</Alias>
              <Type>Umbraco.TextboxMultiple</Type>
              <Definition>c6bac0dd-4ab9-45b1-8e30-e4b619ee5da3</Definition>
              <Tab>Details</Tab>
              <SortOrder>1</SortOrder>
              <Mandatory>True</Mandatory>
            </GenericProperty>
            <GenericProperty>
              <Name>Title</Name>
              <Alias>feedsTitle</Alias>
              <Type>Umbraco.Textbox</Type>
              <Definition>0cc0eba1-9960-42c9-bf9b-60e150b429ae</Definition>
              <Tab>Details</Tab>
              <SortOrder>0</SortOrder>
              <Mandatory>True</Mandatory>
            </GenericProperty>
            <GenericProperty>
              <Name>Image</Name>
              <Alias>feedImage</Alias>
              <Type>Umbraco.MultipleMediaPicker</Type>
              <Definition>93929b9a-93a2-4e2a-b239-d99334440a59</Definition>
              <Tab>Details</Tab>
              <SortOrder>2</SortOrder>
              <Mandatory>False</Mandatory>
            </GenericProperty>
          </GenericProperties>
          <Tabs>
            <Tab>
              <Id>15</Id>
              <Caption>Details</Caption>
              <SortOrder>0</SortOrder>
            </Tab>
          </Tabs>
        </DocumentType>
      </DocumentTypes>
      <Templates />
      <Stylesheets />
      <Macros />
      <DictionaryItems />
      <Languages />
      <DataTypes>
        <DataType Name="Umbraco RSS Feed Content Picker" Id="Umbraco.MultiNodeTreePicker" Definition="ead0d6ec-5816-4d87-8e39-bce032edf51e" DatabaseType="Nvarchar" Folders="UmbracoRssFeeds">
          <PreValues>
            <PreValue Id="20" Value="{&#xD;&#xA;  &quot;type&quot;: &quot;content&quot;&#xD;&#xA;}" Alias="startNode" SortOrder="0" />
            <PreValue Id="21" Value="" Alias="filter" SortOrder="1" />
            <PreValue Id="22" Value="1" Alias="minNumber" SortOrder="2" />
            <PreValue Id="23" Value="" Alias="maxNumber" SortOrder="3" />
            <PreValue Id="24" Value="0" Alias="showOpenButton" SortOrder="4" />
            <PreValue Id="25" Value="0" Alias="showEditButton" SortOrder="5" />
            <PreValue Id="26" Value="0" Alias="showPathOnHover" SortOrder="6" />
          </PreValues>
        </DataType>
        <DataType Name="Umbraco RSS Feed Allowed Document Types" Id="Umbraco.MultipleTextstring" Definition="62fd2622-3ce7-4e0d-9f2e-1b1dcdbaee85" DatabaseType="Ntext" Folders="UmbracoRssFeeds">
          <PreValues>
            <PreValue Id="27" Value="{&quot;Minimum&quot;:0,&quot;Maximum&quot;:0}" Alias="0" SortOrder="0" />
          </PreValues>
        </DataType>
        <DataType Name="Umbraco RSS Feed Levels" Id="Umbraco.Integer" Definition="217583da-877e-44b6-9735-909960dba723" DatabaseType="Integer" Folders="UmbracoRssFeeds">
          <PreValues>
            <PreValue Id="57" Value="0" Alias="min" SortOrder="0" />
            <PreValue Id="58" Value="" Alias="step" SortOrder="1" />
            <PreValue Id="59" Value="" Alias="max" SortOrder="2" />
          </PreValues>
        </DataType>
      </DataTypes>
    </umbPackage>
    

    All looking good I think. My question is, how do I get this in my Nuget package and get the doc types to install when running install-package papermoon.umbraco.umbracorssfeeds?

    I've set up using Grunt following a couple of tutorials and guesswork. My package.json file looks like this:

    {
      "name": "Papermoon.Umbraco.UmbracoRssFeeds",
      "license" : {
        "name": "MIT",
        "url": "http://benpalmer.me"
      },
      "url": "http://benpalmer.me",
      "author": {
        "name": "Ben Palmer",
        "url": "http://benpalmer.me"
      },
      "readme": "Rss feeds",
      "devDependencies": {
        "grunt": "~1.0.1",
        "grunt-contrib-copy": "~1.0.0",
        "grunt-nuget": "~0.2.0",
        "grunt-zip": "~0.17.1",
        "grunt-umbraco-package": "1.0.0",
        "grunt-contrib-clean": "^1.0.0"
      }
    }
    

    And my gruntfile.js:

    module.exports = function(grunt) {
    
        // Load the package JSON file
        var pkg = grunt.file.readJSON('package.json');
    
        // get the root path of the project
        var projectRoot = 'src/' + pkg.name + '/';
    
        // Load information about the assembly
        var assembly = grunt.file.readJSON(projectRoot + 'Properties/AssemblyInfo.json');
    
        // Get the version of the package
        var version = assembly.informationalVersion ? assembly.informationalVersion : assembly.version;
    
        grunt.initConfig({
            pkg: pkg,
            clean: {
                files: [
                    'files/**/*.*'
                ]
            },
            copy: {
                release: {
                    files: [
                        {
                            expand: true,
                            cwd: projectRoot + 'bin/',
                            src: [
                                pkg.name + '.dll',
                                pkg.name + '.xml'
                            ],
                            dest: 'files/bin/'
                        }
                    ]
                }
            },
            nugetpack: {
                release: {
                    src: 'src/' + pkg.name + '/' + pkg.name + '.csproj',
                    dest: 'releases/nuget/',
                    options: {
                        version: version
                    }
                }
            },
            zip: {
                release: {
                    cwd: 'files/',
                    src: [
                        'files/**/*.*'
                    ],
                    dest: 'releases/github/' + pkg.name + '.v' + version + '.zip'
                }
            },
            umbracoPackage: {
                release: {
                    src: 'files/',
                    dest: 'releases/umbraco',
                    options: {
                        name: pkg.name,
                        version: version,
                        url: pkg.url,
                        license: pkg.license.name,
                        licenseUrl: pkg.license.url,
                        author: pkg.author.name,
                        authorUrl: pkg.author.url,
                        readme: pkg.readme,
                        outputName: pkg.name + '.v' + version + '.zip',
                        manifest: 'package.xml'
                    }
                }
            }
        });
    
        grunt.loadNpmTasks('grunt-contrib-clean');
        grunt.loadNpmTasks('grunt-contrib-copy');
        grunt.loadNpmTasks('grunt-nuget');
        grunt.loadNpmTasks('grunt-zip');
        grunt.loadNpmTasks('grunt-umbraco-package');
    
        grunt.registerTask('dev', ['clean', 'copy', 'nugetpack', 'zip', 'umbracoPackage']);
        grunt.registerTask('default', ['dev']);
    
    };
    

    This all works nicely but as I said, I just can't get my head around how to make use of the package.xml file.

    Has anyone done this? Any suggestions? Any and all help would be massively appreciated!

    Even if you've not done the automated part, just figuring out where the xml should go would out me on the right track I think.

    Thanks

    Ben

  • Gabor Ferencz 40 posts 181 karma points
    Dec 11, 2020 @ 14:04
    Gabor Ferencz
    0

    HI Ben,

    Have you ever found a solution to this? We're trying to do the same thing, and not really finding much success...

    Thanks, Gabor

  • Ben Palmer 180 posts 866 karma points c-trib
    Dec 16, 2020 @ 10:25
    Ben Palmer
    0

    Hi Gabor,

    Unfortunately not, I don't think there's a way to do this without rolling out your own code.

    In the end, I ended up doing this using the various services that Umbraco provides. I set up a few factories that would get auto-detected on first boot and run - this is a pretty old post so I'm not sure that I have the code.

    In Umbraco 8, I've got a small proof of concept which I've set up to allow me to create documents using a package.manifest file but ultimately it's the same set up, I have some code on startup that reads the file. This then uses Umbraco's services to create the content types etc.

    Thanks,

    Ben

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Dec 14, 2020 @ 13:34
    David Brendel
    0

    Hi Gabor,

    there is no nativ way of installing things from the package.xml when you install a nuget package. The way is mostly to write some code that runs on startup and install it either via the services or using the actual package installer which both is not quite trivial.

    For example the articulate package does something like this: https://github.com/Shazwazza/Articulate/blob/919122cc0d630704e6e240b6ffe2e4ec034f3717/src/Articulate/Packaging/ArticulateDataInstaller.cs

    Regards David

Please Sign in or register to post replies

Write your reply to:

Draft