Public/Convert-NcrementManifestToNugetTokens.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<#
.SYNOPSIS
Serializes a [Manifest] object to a nuget tokens.
 
.PARAMETER Manifest
The [Manifest] object.
 
.INPUTS
[Manifest]
 
.OUTPUTS
[String]
 
.EXAMPLE
&nuget -Properties "$(Get-NcrementManifest | Convert-NcrementManifestToNugetTokens)";
In this example, the [Manifest] is being piped to the function to be used as the value for the 'nuget.exe' -Properties argument.
 
.LINK
Get-NcrementManifest
 
.LINK
New-NcrementManifest
#>


function Convert-NcrementManifestToNugetTokens([Parameter(Mandatory, ValueFromPipeline)]$Manifest)
{
    $token = [System.Text.StringBuilder]::new();
    $exclusionList = @("Path", "BranchSuffixMap", "Version");

    foreach ($prop in $Manifest.PSObject.Properties)
    {
        if (($exclusionList -notcontains $prop.Name) -and (-not [string]::IsNullOrEmpty($prop.Value)))
        {
            $token.AppendFormat("{0}={1};", $prop.Name, $prop.Value) | Out-Null;
        }
    }

    return $token.ToString();
}

Set-Alias -Name "n-token" -Value  "Convert-NcrementManifestToNugetTokens";
Set-Alias -Name "ConvertTo-NuGetTokens" -Value  "Convert-NcrementManifestToNugetTokens";