--- /dev/null
+param($installPath, $toolsPath, $package, $project)\r
+\r
+# open json.net splash page on package install\r
+# don't open if json.net is installed as a dependency\r
+\r
+try\r
+{\r
+ $url = "http://www.newtonsoft.com/json/install?version=" + $package.Version\r
+ $dte2 = Get-Interface $dte ([EnvDTE80.DTE2])\r
+\r
+ if ($dte2.ActiveWindow.Caption -eq "Package Manager Console")\r
+ {\r
+ # user is installing from VS NuGet console\r
+ # get reference to the window, the console host and the input history\r
+ # show webpage if "install-package newtonsoft.json" was last input\r
+\r
+ $consoleWindow = $(Get-VSComponentModel).GetService([NuGetConsole.IPowerConsoleWindow])\r
+\r
+ $props = $consoleWindow.GetType().GetProperties([System.Reflection.BindingFlags]::Instance -bor `\r
+ [System.Reflection.BindingFlags]::NonPublic)\r
+\r
+ $prop = $props | ? { $_.Name -eq "ActiveHostInfo" } | select -first 1\r
+ if ($prop -eq $null) { return }\r
+ \r
+ $hostInfo = $prop.GetValue($consoleWindow)\r
+ if ($hostInfo -eq $null) { return }\r
+\r
+ $history = $hostInfo.WpfConsole.InputHistory.History\r
+\r
+ $lastCommand = $history | select -last 1\r
+\r
+ if ($lastCommand)\r
+ {\r
+ $lastCommand = $lastCommand.Trim().ToLower()\r
+ if ($lastCommand.StartsWith("install-package") -and $lastCommand.Contains("newtonsoft.json"))\r
+ {\r
+ $dte2.ItemOperations.Navigate($url) | Out-Null\r
+ }\r
+ }\r
+ }\r
+ else\r
+ {\r
+ # user is installing from VS NuGet dialog\r
+ # get reference to the window, then smart output console provider\r
+ # show webpage if messages in buffered console contains "installing...newtonsoft.json" in last operation\r
+\r
+ $instanceField = [NuGet.Dialog.PackageManagerWindow].GetField("CurrentInstance", [System.Reflection.BindingFlags]::Static -bor `\r
+ [System.Reflection.BindingFlags]::NonPublic)\r
+\r
+ $consoleField = [NuGet.Dialog.PackageManagerWindow].GetField("_smartOutputConsoleProvider", [System.Reflection.BindingFlags]::Instance -bor `\r
+ [System.Reflection.BindingFlags]::NonPublic)\r
+\r
+ if ($instanceField -eq $null -or $consoleField -eq $null) { return }\r
+\r
+ $instance = $instanceField.GetValue($null)\r
+\r
+ if ($instance -eq $null) { return }\r
+\r
+ $consoleProvider = $consoleField.GetValue($instance)\r
+ if ($consoleProvider -eq $null) { return }\r
+\r
+ $console = $consoleProvider.CreateOutputConsole($false)\r
+\r
+ $messagesField = $console.GetType().GetField("_messages", [System.Reflection.BindingFlags]::Instance -bor `\r
+ [System.Reflection.BindingFlags]::NonPublic)\r
+ if ($messagesField -eq $null) { return }\r
+\r
+ $messages = $messagesField.GetValue($console)\r
+ if ($messages -eq $null) { return }\r
+\r
+ $operations = $messages -split "=============================="\r
+\r
+ $lastOperation = $operations | select -last 1\r
+\r
+ if ($lastOperation)\r
+ {\r
+ $lastOperation = $lastOperation.ToLower()\r
+\r
+ $lines = $lastOperation -split "`r`n"\r
+\r
+ $installMatch = $lines | ? { $_.StartsWith("------- installing...newtonsoft.json ") } | select -first 1\r
+\r
+ if ($installMatch)\r
+ {\r
+ $dte2.ItemOperations.Navigate($url) | Out-Null\r
+ }\r
+ }\r
+ }\r
+}\r
+catch\r
+{\r
+ try\r
+ {\r
+ $pmPane = $dte2.ToolWindows.OutputWindow.OutputWindowPanes.Item("Package Manager")\r
+\r
+ $selection = $pmPane.TextDocument.Selection\r
+ $selection.StartOfDocument($false)\r
+ $selection.EndOfDocument($true)\r
+\r
+ if ($selection.Text.StartsWith("Attempting to gather dependencies information for package 'Newtonsoft.Json." + $package.Version + "'"))\r
+ {\r
+ $dte2.ItemOperations.Navigate($url) | Out-Null\r
+ }\r
+ }\r
+ catch\r
+ {\r
+ # stop potential errors from bubbling up\r
+ # worst case the splash page won't open \r
+ }\r
+}\r
+\r
+# still yolo
\ No newline at end of file