1 param
($installPath, $toolsPath, $package, $project)
3 # open json.net splash page on package install
4 # don't open if json.net is installed as a dependency
8 $url = "http://www.newtonsoft.com/json/install?version=" + $package.Version
9 $dte2 = Get-Interface
$dte ([EnvDTE80
.DTE2
])
11 if ($dte2.ActiveWindow
.Caption
-eq
"Package Manager Console")
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
17 $consoleWindow = $(Get-VSComponentModel)
.GetService
([NuGetConsole
.IPowerConsoleWindow
])
19 $props = $consoleWindow.GetType
().GetProperties
([System
.Reflection
.BindingFlags
]::Instance
-bor `
20 [System
.Reflection
.BindingFlags
]::NonPublic
)
22 $prop = $props | ? { $_.Name
-eq
"ActiveHostInfo" } | select -first
1
23 if ($prop -eq
$null) { return }
25 $hostInfo = $prop.GetValue
($consoleWindow)
26 if ($hostInfo -eq
$null) { return }
28 $history = $hostInfo.WpfConsole
.InputHistory
.History
30 $lastCommand = $history | select -last
1
34 $lastCommand = $lastCommand.Trim
().ToLower
()
35 if ($lastCommand.StartsWith
("install-package") -and
$lastCommand.Contains
("newtonsoft.json"))
37 $dte2.ItemOperations
.Navigate
($url) | Out-Null
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
47 $instanceField = [NuGet
.Dialog
.PackageManagerWindow
].GetField
("CurrentInstance", [System
.Reflection
.BindingFlags
]::Static
-bor `
48 [System
.Reflection
.BindingFlags
]::NonPublic
)
50 $consoleField = [NuGet
.Dialog
.PackageManagerWindow
].GetField
("_smartOutputConsoleProvider", [System
.Reflection
.BindingFlags
]::Instance
-bor `
51 [System
.Reflection
.BindingFlags
]::NonPublic
)
53 if ($instanceField -eq
$null -or
$consoleField -eq
$null) { return }
55 $instance = $instanceField.GetValue
($null)
57 if ($instance -eq
$null) { return }
59 $consoleProvider = $consoleField.GetValue
($instance)
60 if ($consoleProvider -eq
$null) { return }
62 $console = $consoleProvider.CreateOutputConsole
($false)
64 $messagesField = $console.GetType
().GetField
("_messages", [System
.Reflection
.BindingFlags
]::Instance
-bor `
65 [System
.Reflection
.BindingFlags
]::NonPublic
)
66 if ($messagesField -eq
$null) { return }
68 $messages = $messagesField.GetValue
($console)
69 if ($messages -eq
$null) { return }
71 $operations = $messages -split
"=============================="
73 $lastOperation = $operations | select -last
1
77 $lastOperation = $lastOperation.ToLower
()
79 $lines = $lastOperation -split
"`r`n"
81 $installMatch = $lines | ? { $_.StartsWith
("------- installing...newtonsoft.json ") } | select -first
1
85 $dte2.ItemOperations
.Navigate
($url) | Out-Null
94 $pmPane = $dte2.ToolWindows
.OutputWindow
.OutputWindowPanes
.Item
("Package Manager")
96 $selection = $pmPane.TextDocument
.Selection
97 $selection.StartOfDocument
($false)
98 $selection.EndOfDocument
($true)
100 if ($selection.Text
.StartsWith
("Attempting to gather dependencies information for package 'Newtonsoft.Json." + $package.Version
+ "'"))
102 # don't show on upgrade
103 if (!$selection.Text
.Contains
("Removed package"))
105 $dte2.ItemOperations
.Navigate
($url) | Out-Null
111 # stop potential errors from bubbling up
112 # worst case the splash page won't open