Public/ConvertTo-NuSpec.ps1

Set-StrictMode -Version Latest

function ConvertTo-NuSpec {
   [CmdletBinding()]
   param
   (      
      [Parameter(Position = 0, Mandatory = $true)]
      [string]
      $Path
   )

   Process {
      # Load psd1
      $manifest = Test-ModuleManifest -Path $Path

      Write-Verbose $manifest

      $NuspecPath = $Path.Replace('.psd1', '.nuspec')

      Write-Verbose $NuspecPath

      try {
         $projectUrl = $manifest.PrivateData.PSData.ProjectUri
         Write-Verbose $projectUrl
      }
      catch {
         throw 'You must set the Project Uri in PrivateData.PSData.ProjectUri'
      }

      # Populate the nuspec elements
      $nuspec = @"
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
   <metadata>
      <id>$($manifest.Name)</id>
      <version>$($manifest.Version)</version>
      <authors>$($manifest.Author)</authors>
      <owners>$($manifest.CompanyName)</owners>
      <projectUrl>$projectUrl</projectUrl>
      <requireLicenseAcceptance>false</requireLicenseAcceptance>
      <description>$($manifest.Description)</description>
      <releaseNotes />
      <copyright>$($manifest.Copyright)</copyright>
      <tags></tags>
   </metadata>
</package>
"@


      Write-Verbose $nuspec 

      Set-Content -Value $nuspec -Path $NuspecPath -Force
   }
}