markus / packages / Newtonsoft.Json.6.0.4 / tools / install.ps1 @ fc6ec385
이력 | 보기 | 이력해설 | 다운로드 (3.06 KB)
1 | 787a4489 | KangIngu | param($installPath, $toolsPath, $package, $project) |
---|---|---|---|
2 | |||
3 | # open json.net splash page on package install |
||
4 | # don't open if json.net is installed as a dependency |
||
5 | |||
6 | try |
||
7 | { |
||
8 | $url = "http://james.newtonking.com/json" |
||
9 | $dte2 = Get-Interface $dte ([EnvDTE80.DTE2]) |
||
10 | |||
11 | if ($dte2.ActiveWindow.Caption -eq "Package Manager Console") |
||
12 | { |
||
13 | # user is installing from VS NuGet console |
||
14 | # get reference to the window, the console host and the input history |
||
15 | # show webpage if "install-package newtonsoft.json" was last input |
||
16 | |||
17 | $consoleWindow = $(Get-VSComponentModel).GetService([NuGetConsole.IPowerConsoleWindow]) |
||
18 | |||
19 | $props = $consoleWindow.GetType().GetProperties([System.Reflection.BindingFlags]::Instance -bor ` |
||
20 | [System.Reflection.BindingFlags]::NonPublic) |
||
21 | |||
22 | $prop = $props | ? { $_.Name -eq "ActiveHostInfo" } | select -first 1 |
||
23 | if ($prop -eq $null) { return } |
||
24 | |||
25 | $hostInfo = $prop.GetValue($consoleWindow) |
||
26 | if ($hostInfo -eq $null) { return } |
||
27 | |||
28 | $history = $hostInfo.WpfConsole.InputHistory.History |
||
29 | |||
30 | $lastCommand = $history | select -last 1 |
||
31 | |||
32 | if ($lastCommand) |
||
33 | { |
||
34 | $lastCommand = $lastCommand.Trim().ToLower() |
||
35 | if ($lastCommand.StartsWith("install-package") -and $lastCommand.Contains("newtonsoft.json")) |
||
36 | { |
||
37 | $dte2.ItemOperations.Navigate($url) | Out-Null |
||
38 | } |
||
39 | } |
||
40 | } |
||
41 | else |
||
42 | { |
||
43 | # user is installing from VS NuGet dialog |
||
44 | # get reference to the window, then smart output console provider |
||
45 | # show webpage if messages in buffered console contains "installing...newtonsoft.json" in last operation |
||
46 | |||
47 | $instanceField = [NuGet.Dialog.PackageManagerWindow].GetField("CurrentInstance", [System.Reflection.BindingFlags]::Static -bor ` |
||
48 | [System.Reflection.BindingFlags]::NonPublic) |
||
49 | $consoleField = [NuGet.Dialog.PackageManagerWindow].GetField("_smartOutputConsoleProvider", [System.Reflection.BindingFlags]::Instance -bor ` |
||
50 | [System.Reflection.BindingFlags]::NonPublic) |
||
51 | if ($instanceField -eq $null -or $consoleField -eq $null) { return } |
||
52 | |||
53 | $instance = $instanceField.GetValue($null) |
||
54 | if ($instance -eq $null) { return } |
||
55 | |||
56 | $consoleProvider = $consoleField.GetValue($instance) |
||
57 | if ($consoleProvider -eq $null) { return } |
||
58 | |||
59 | $console = $consoleProvider.CreateOutputConsole($false) |
||
60 | |||
61 | $messagesField = $console.GetType().GetField("_messages", [System.Reflection.BindingFlags]::Instance -bor ` |
||
62 | [System.Reflection.BindingFlags]::NonPublic) |
||
63 | if ($messagesField -eq $null) { return } |
||
64 | |||
65 | $messages = $messagesField.GetValue($console) |
||
66 | if ($messages -eq $null) { return } |
||
67 | |||
68 | $operations = $messages -split "==============================" |
||
69 | |||
70 | $lastOperation = $operations | select -last 1 |
||
71 | |||
72 | if ($lastOperation) |
||
73 | { |
||
74 | $lastOperation = $lastOperation.ToLower() |
||
75 | |||
76 | $lines = $lastOperation -split "`r`n" |
||
77 | |||
78 | $installMatch = $lines | ? { $_.StartsWith("------- installing...newtonsoft.json ") } | select -first 1 |
||
79 | |||
80 | if ($installMatch) |
||
81 | { |
||
82 | $dte2.ItemOperations.Navigate($url) | Out-Null |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | catch |
||
88 | { |
||
89 | # stop potential errors from bubbling up |
||
90 | # worst case the splash page won't open |
||
91 | } |
||
92 | |||
93 | # yolo |