nuspec metadata extensibility

Editor
Jan 7, 2011 at 2:31 PM

I don't think this was asked before, so here's my scenario:

I'd like to extend the package metadata information with data that can be used by a powershell script. Typical example:
<package ...>
  <metadata>
     ....
     <extensions>
       <vs:reference xmlns:vs="vs-automation">PresentationFramework<vs:reference>
This metadata information could be read (plain XML reading from powershell on init.ps1 for example or install.ps1) and some action could happen (in this case, adding a reference to a library that is not included in lib but which is necessary maybe for some content files?
Another example:
<vs:import>VSSDK.targets<vs:import>
(you get the idea :))
I've added this support in the schema as well as the code, added a unit test and made sure the rest still run green. Essentially, added an <xs:element name="extensions"> element to the metadata <xs:all>, and inside that, allowed any attribute (on ##other namespaces) as well as any element (both on ##other as well as ##local -that is, empty- namespace). This way, we prevent potential collisions if the nuget schema is evolved in the future with more elements, even under <extensions> (say nuget starts using this as a general-purpose extensibility/automation mechanism itself).
My fork is at https://hg01.codeplex.com/forks/dcazzulino/extensibleschema. Changes were pretty trivial and very focused.
Is this useful (I know it would be for me!)? Thoughts?

/kzu

--
Daniel Cazzulino | Developer Lead | MS MVP | Clarius Consulting | +1 425.329.3471

 

 

Coordinator
Jan 7, 2011 at 3:49 PM

Out of curiosity, if you have metadata specific to your package, why not just add another custom metadata file to your package?

Editor
Jan 7, 2011 at 4:29 PM

But then I'd have to manage different aspects of my package metadata in separate files, when it may be conceptually all part of the same thing.

But you're right, I could have an extra file in the package, say, vsautomation.xml, and invoke a dependency-provided command to process it:

<dependencies>
  <dependency id="FancyVsAutomation" version="1.0.0" />
</depencencies>

and install.ps1 could have a single line like:

Process-VsAutomation $installPath, $project

(or whatever)

Still feels like some out of the box extension processing should be possible and cool, so that package authors can just declare their dependency and leverage plain markup to make things happen.

Say the "FancyVsAutomation" had a powershell hook to say "I can process extensions of namespace http://foo", and NuGet would automatically call it on init/install/uninstall of any package that uses extensions in that namespace....

 

I think it could be pretty powerful to add mini-dsls via XML that can be easily implemented in powershell by extension authors. Just brainstorming :). I can give that full automatic thing a try if you think it's worth it.

Coordinator
Jan 7, 2011 at 4:37 PM

I’m not opposed to making NuSpec extensible in that way. I just haven’t put much thought behind it. I guess you could experiment with both approaches and let us know the pros/cons for each. J

Editor
Jan 7, 2011 at 6:48 PM

I accepted the @async change but have to reject the xsd schema change. I think it's better to keep the .nuspec file clean. We have many components which depend on it, including the gallery server. You can easily add a custom file to your package which contain extra medata for your needs.
Not sure if this means a decision has been made already or if you still think it's worth exploring this idea.
Changes in the schema have no impact on anything else as it's just one more optional element in the metadata, with skip processing for anything inside it. 
Developer
Jan 7, 2011 at 11:19 PM

How do you consume the custom metadata?

Editor
Jan 8, 2011 at 3:17 PM

I'm gonna experiment with the external solution first (a plain xml alongside the spec file, and powershell that locates it by convention)

Jan 31, 2011 at 11:23 PM

Hi,

I have a similar requirement.
I'm using NuGet to allow people to extend my web application. A power user will be able to select an extension from a back-office and it will add feature to the system (as Orchard do). These extensions are specific to our application and we need to add some parameters.

I've got 2 ways :

  1. Add my custom metadata file to the package and get it from the ZipPackage class
  2. Extend the current .nuspec file by adding xml namespace, etc.

From what I read here, the solution #2 would be the best. This confirms my choice, do you agree?

Thanks,

Dec 26, 2012 at 1:46 AM

I have an interest similar to that expressed by cdurand.  That is, consolidation of nuspec metadata with custom "plugin" metadata.  I would like to add a namespace to the root package:

<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd" xmlns:shrm="http://info.mystuff.com/extensions/metadata.xsd">...

If I do that, and start adding package sub-elements with the "shrm" namespace, can I still upload nuget packages to the nuget.org package source?  Will nuget strip-out my extraneous namespace data or reject the upload?

If the answer is "you must create your own custom nuget repository, with a custom nuget XSD for this", then this is not what I want.  Curious... 

Developer
Dec 26, 2012 at 6:00 PM

I don't know for sure either. The best way to know is to try it yourself. To avoid polluting the main feed, you can upload your package to http://prevew.nuget.org.

Jan 25, 2013 at 10:45 PM

Did you ever figure this out?