+p_xml: version="1.0" encoding="utf-8"
package:
  +@xmlns: http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd
  metadata:
    id: {{ .id | default "" }}
    version: {{ .version | default ""  }}
    description: {{ .description | default ""  }}
    authors: "{{ join ", " .authors | default "" }}"
    
    title: {{ .title | default "" }}
    projectUrl: {{ .projectUrl | default "" }}
    licenseUrl: {{ .licenseUrl | default "" }}
    {{- with .license }}
    license:
      {{- if .content }}
      +content: {{ .content }}
      {{- end }}
      {{- if .type }}
      +@type: {{ .type }}
      {{- end }}
    {{- end }}
    icon: {{ .icon | default "" }}
    iconUrl: {{ .iconUrl | default "" }}
    requireLicenseAcceptance: {{ .requireLicenseAcceptance | default "" }}
    developmentDependency: {{ .developmentDependency | default "" }}
    {{- if .copyright }}
    copyright: {{ tpl (toYaml .copyright) $ }}
    {{- end }}
    summary: {{ .summary | default "" }}
    releaseNotes: {{ .releaseNotes | default "" }}
    language: {{ .language | default "" }}
    tags: "{{ join ", " .tags | default "" }}"
    {{- with .repository }}  
    repository:
      {{- if .type }}
      +@type: {{ .type }}
      {{- end }}
      {{- if .url }}
      +@url: {{ .url }}
      {{- end }}
      {{- if .branch }}
      +@branch: {{ .branch }}
      {{- end }}
      {{- if .commit }}
      +@commit: {{ .commit }}
      {{- end }}
    {{- end }}

    {{- with $.source }}
    {{- $path := print (default "." $.path) "/" (default "." .path) | clean }}
    dependencies:
      group:
      {{- range $item := .groups  }}
      {{- if and $item.framework }}
      - +@targetFramework: {{ $item.framework }}
        dependency:
        {{- range $dep := $item.dependencies }}
        - +@id: {{ $dep.id }}
          +@version: {{ $dep.version }}
          +@exclude: "{{ join ", " $dep.exclude }}"
        {{- end }}
      {{- end }}
      {{- end }}
    references:
      group:
      {{- range $item := .groups  }}
      {{- if and $item.framework $item.references }}
      - +@targetFramework: {{ $item.framework }}
        {{- range $ref := $item.references }}
        - reference:
            +@file: {{ print $path "/" $ref.name | clean }}
        {{- end }}
      {{- end }}
      {{- end }}
    frameworkAssemblies:
      frameworkAssembly:
      {{- range $item := .groups }}
      {{- range $ref := $item.assemblies }}
      - +@assemblyName: {{ $ref.name }}
      {{- if $item.framework }}
        +@targetFramework: {{ $item.framework }}
      {{- end }}
      {{- end }}
      {{- end }}
    {{- end }}
    {{- with $.content }}
    {{- $path := print (default "." $.path) "/" (default "." .path) | clean }}
    contentFiles:
      files:
      {{- range $file := .files }}
      - +@include: {{ print $path "/" $file.include | clean }}
        {{- if $file.exclude }}
        +@exclude: {{ print $path "/" $file.exclude | clean }}
        {{- end }}
        {{- if $file.buildAction }}
        +@buildAction: {{ $file.buildAction }}
        {{- end }}
        {{- if $file.copyToOutput }}
        +@copyToOutput: {{ $file.copyToOutput }}
        {{- end }}
        {{- if $file.flatten }}
        +@flatten: {{ $file.flatten }}
        {{- end }}
      {{- end }}
    {{- end }}
  {{- with $.source }}
  {{- $path := print (default "." $.path) "/" (default "." .path) | clean }}
  files:
    file:
    {{- range $item := .groups  }}
    {{- range $file := $item.files }}
    - +@src: {{ print $path "/" $file.name | clean }}
      {{- if $item.framework }}
      +@target: {{ print "lib/" $item.framework "/" (default $file.target ".") | clean }}
      {{- else if $file.target }}
      +@target: {{ $file.target }}
      {{- end }}
      {{- if $file.exclude }}
      +@exclude: {{ print $path "/" $file.exclude | clean }}
      {{- end }}
    {{- end }}
    {{- if $item.framework }}
    {{- range $dll := $item.dlls }}
    - +@src: {{ print $path "/" $dll.name ".dll" | clean }}
      +@target: {{ print "lib/" $item.framework "/" (default $item.target ".") | clean }}
    {{- if ($dll.hasPdb | default true) }}
    - +@src: {{ print $path "/" $dll.name ".pdb" | clean }}
      +@target: {{ print "lib/" $item.framework "/" (default $item.target ".") | clean }}
    {{- end }}
    {{- end }}
    {{- end }}
    {{- end }}
  {{- end }}
