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 $NuspecPath = $Path.Replace('.psd1', '.nuspec') $projectUrl = $null if($manifest.PrivateData.PSData["ProjectUri"]) { $projectUrl = $manifest.PrivateData.PSData.ProjectUri } # Populate the nuspec elements $sb = New-Object System.Text.StringBuilder $null = $sb.Append('<?xml version="1.0"?>') $null = $sb.Append("`r`n") $null = $sb.Append('<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">') $null = $sb.Append("`r`n") $null = $sb.Append("<metadata>`r`n") $null = $sb.Append("<id>$($manifest.Name)</id>`r`n") $null = $sb.Append("<version>$($manifest.Version)</version>`r`n") $null = $sb.Append("<authors>$($manifest.Author)</authors>`r`n") $null = $sb.Append("<owners>$($manifest.CompanyName)</owners>`r`n") if ($null -ne $projectUrl) { $null = $sb.Append("<projectUrl>$projectUrl</projectUrl>`r`n") } $null = $sb.Append("<requireLicenseAcceptance>false</requireLicenseAcceptance>`r`n") $null = $sb.Append("<description>$($manifest.Description)</description>`r`n") $null = $sb.Append("<releaseNotes />`r`n") $null = $sb.Append("<copyright>$($manifest.Copyright)</copyright>`r`n") $null = $sb.Append("<tags>`r`n") $null = $sb.Append("</tags>`r`n") $null = $sb.Append("<dependencies>`r`n") foreach ($d in $manifest.RequiredModules) { $null = $sb.Append('<dependency id="') $null = $sb.Append($d.Name) $null = $sb.Append('" />') $null = $sb.Append("`r`n") } $null = $sb.Append("</dependencies>`r`n") $null = $sb.Append("</metadata>") $null = $sb.Append("</package>") Set-Content -Value $sb.ToString() -Path $NuspecPath -Force } } |