/sdk/nuget-content/install.ps1

https://gitlab.com/vectorci/aws-sdk-net · Powershell · 179 lines · 113 code · 41 blank · 25 comment · 35 complexity · 757f1ee7f41fd94dd055d1c2bb9d592b MD5 · raw file

  1. param($installPath, $toolsPath, $package, $project)
  2. # This install script is based on the Newtonsoft.Json NuGet install script and is licensed under the MIT License.
  3. # The MIT License (MIT)
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy of this software
  6. # and associated documentation files (the "Software"), to deal in the Software without restriction,
  7. # including without limitation the rights to use, copy, modify, merge, publish, distribute,
  8. # sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  12. #
  13. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
  14. # BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  15. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  16. # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  17. # open AWSSDK splash page on package install
  18. # don't open if AWSSDK is installed as a dependency
  19. try
  20. {
  21. $url = "http://aws-nuget-landingpages.s3-website-us-east-1.amazonaws.com/awssdk.version.3.html?package=" + $package
  22. $dte2 = Get-Interface $dte ([EnvDTE80.DTE2])
  23. if ($dte2.ActiveWindow.Caption -eq "Package Manager Console")
  24. {
  25. # user is installing from VS NuGet console
  26. # get reference to the window, the console host and the input history
  27. # show webpage if "install-package AWSSDK" was last input
  28. $consoleWindow = $(Get-VSComponentModel).GetService([NuGetConsole.IPowerConsoleWindow])
  29. $props = $consoleWindow.GetType().GetProperties([System.Reflection.BindingFlags]::Instance -bor `
  30. [System.Reflection.BindingFlags]::NonPublic)
  31. $prop = $props | ? { $_.Name -eq "ActiveHostInfo" } | select -first 1
  32. if ($prop -eq $null) { return }
  33. $hostInfo = $prop.GetValue($consoleWindow)
  34. if ($hostInfo -eq $null) { return }
  35. $history = $hostInfo.WpfConsole.InputHistory.History
  36. $lastCommand = $history | select -last 1
  37. if ($lastCommand)
  38. {
  39. $lastCommand = $lastCommand.Trim().ToLower()
  40. if ($lastCommand.StartsWith("install-package") -and $lastCommand.Contains("awssdk"))
  41. {
  42. $dte2.ItemOperations.Navigate($url) | Out-Null
  43. }
  44. }
  45. }
  46. else
  47. {
  48. # user is installing from VS NuGet dialog
  49. # get reference to the window, then smart output console provider
  50. # show webpage if messages in buffered console contains "installing...AWSSDK" in last operation
  51. $instanceField = [NuGet.Dialog.PackageManagerWindow].GetField("CurrentInstance", [System.Reflection.BindingFlags]::Static -bor `
  52. [System.Reflection.BindingFlags]::NonPublic)
  53. $consoleField = [NuGet.Dialog.PackageManagerWindow].GetField("_smartOutputConsoleProvider", [System.Reflection.BindingFlags]::Instance -bor `
  54. [System.Reflection.BindingFlags]::NonPublic)
  55. if ($instanceField -eq $null -or $consoleField -eq $null) { return }
  56. $instance = $instanceField.GetValue($null)
  57. if ($instance -eq $null) { return }
  58. $consoleProvider = $consoleField.GetValue($instance)
  59. if ($consoleProvider -eq $null) { return }
  60. $console = $consoleProvider.CreateOutputConsole($false)
  61. $messagesField = $console.GetType().GetField("_messages", [System.Reflection.BindingFlags]::Instance -bor `
  62. [System.Reflection.BindingFlags]::NonPublic)
  63. if ($messagesField -eq $null) { return }
  64. $messages = $messagesField.GetValue($console)
  65. if ($messages -eq $null) { return }
  66. $operations = $messages -split "=============================="
  67. $lastOperation = $operations | select -last 1
  68. if ($lastOperation)
  69. {
  70. $lastOperation = $lastOperation.ToLower()
  71. $lines = $lastOperation -split "`r`n"
  72. $installMatch = $lines | ? { $_.StartsWith("------- installing...awssdk") } | select -first 1
  73. if ($installMatch)
  74. {
  75. $dte2.ItemOperations.Navigate($url) | Out-Null
  76. }
  77. }
  78. }
  79. }
  80. catch
  81. {
  82. try
  83. {
  84. $pmPane = $dte2.ToolWindows.OutputWindow.OutputWindowPanes.Item("Package Manager")
  85. $selection = $pmPane.TextDocument.Selection
  86. $selection.StartOfDocument($false)
  87. $selection.EndOfDocument($true)
  88. if ($selection.Text.StartsWith("Installing 'awssdk"))
  89. {
  90. $dte2.ItemOperations.Navigate($url) | Out-Null
  91. }
  92. }
  93. catch
  94. {
  95. # stop potential errors from bubbling up
  96. # worst case the splash page won't open
  97. }
  98. }
  99. function UpdateCurrentProjectsConfigFile([string]$name)
  100. {
  101. $config = $project.ProjectItems | where {$_.Name -eq "Web.config"}
  102. if ($config -eq $null)
  103. {
  104. $config = $project.ProjectItems | where {$_.Name -eq "App.config"}
  105. if ($config -eq $null)
  106. {
  107. return
  108. }
  109. }
  110. $localPath = $config.Properties | where {$_.Name -eq "LocalPath"}
  111. UpdateConfigFile($localPath.Value, $name)
  112. }
  113. function UpdateConfigFile([string]$configFilePath, [string]$name)
  114. {
  115. $references = (Select-String $configFilePath -pattern "AWSProfileName").Matches.Count
  116. If( $references -ne 0)
  117. {
  118. Write-Host "AWSProfileName already exists in config file"
  119. return
  120. }
  121. $xml = New-Object xml
  122. $xml.Load($configFilePath)
  123. $appSettingNode = $xml.SelectSingleNode("configuration/appSettings/add[@key = 'AWSProfileName']")
  124. Write-Host "Adding AWSProfileName appSetting to " $configFilePath
  125. $appSettingsNode = $xml.SelectSingleNode("configuration/appSettings")
  126. if ($appSettingsNode -eq $null)
  127. {
  128. $appSettingsNode = $xml.CreateElement("appSettings")
  129. $xml.DocumentElement.AppendChild($appSettingsNode)
  130. }
  131. if ($name -eq "")
  132. {
  133. $comment = $xml.CreateComment("AWSProfileName is used to reference an account that has been registered with the SDK.`r`nIf using AWS Toolkit for Visual Studio then this value is the same value shown in the AWS Explorer.`r`nIt is also possible to register an account using the <solution-dir>/packages/AWSSDK-X.X.X.X/tools/account-management.ps1 PowerShell script`r`nthat is bundled with the nuget package under the tools folder.`r`n`r`n`t`t<add key=""AWSProfileName"" value="""" />`r`n")
  134. $appSettingsNode.AppendChild($comment)
  135. }
  136. $xml.Save($configFilePath)
  137. }
  138. UpdateCurrentProjectsConfigFile ""