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