Private/Test-VSIXManifest.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
function Test-VSIXManifest{
    Param(
        [Parameter(ValueFromPipeline)]
        $InputObject
    )

    $path = ConvertTo-Path $InputObject;
    if ($path -and ($path.EndsWith(".vsixmanifest")))
    {
        [xml]$doc = $null;
        try { $doc = Get-Content $path; } catch { return $false; }
        $ns = [System.Xml.XmlNamespaceManager]::new($doc.NameTable);
        $ns.AddNamespace("x", "http://schemas.microsoft.com/developer/vsx-schema/2011");

        try
        {
            $matchFound = ($doc.SelectSingleNode("//x:Metadata", $ns) -ne $null);
            if ($matchFound)
            {
                return [PSCustomObject]@{
                    "Xmlns"=$ns;
                    "Document"=$doc;
                    "Path"=$path;
                };
            }
        }
        catch { return $false; }
    }

    return $false;
}