/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
- param($installPath, $toolsPath, $package, $project)
- # This install script is based on the Newtonsoft.Json NuGet install script and is licensed under the MIT License.
- # The MIT License (MIT)
- #
- # Permission is hereby granted, free of charge, to any person obtaining a copy of this software
- # and associated documentation files (the "Software"), to deal in the Software without restriction,
- # including without limitation the rights to use, copy, modify, merge, publish, distribute,
- # sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- # furnished to do so, subject to the following conditions:
- #
- # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- #
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
- # BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- # 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.
- # open AWSSDK splash page on package install
- # don't open if AWSSDK is installed as a dependency
- try
- {
- $url = "http://aws-nuget-landingpages.s3-website-us-east-1.amazonaws.com/awssdk.version.3.html?package=" + $package
- $dte2 = Get-Interface $dte ([EnvDTE80.DTE2])
- if ($dte2.ActiveWindow.Caption -eq "Package Manager Console")
- {
- # user is installing from VS NuGet console
- # get reference to the window, the console host and the input history
- # show webpage if "install-package AWSSDK" was last input
- $consoleWindow = $(Get-VSComponentModel).GetService([NuGetConsole.IPowerConsoleWindow])
- $props = $consoleWindow.GetType().GetProperties([System.Reflection.BindingFlags]::Instance -bor `
- [System.Reflection.BindingFlags]::NonPublic)
- $prop = $props | ? { $_.Name -eq "ActiveHostInfo" } | select -first 1
- if ($prop -eq $null) { return }
-
- $hostInfo = $prop.GetValue($consoleWindow)
- if ($hostInfo -eq $null) { return }
- $history = $hostInfo.WpfConsole.InputHistory.History
- $lastCommand = $history | select -last 1
- if ($lastCommand)
- {
- $lastCommand = $lastCommand.Trim().ToLower()
- if ($lastCommand.StartsWith("install-package") -and $lastCommand.Contains("awssdk"))
- {
- $dte2.ItemOperations.Navigate($url) | Out-Null
- }
- }
- }
- else
- {
- # user is installing from VS NuGet dialog
- # get reference to the window, then smart output console provider
- # show webpage if messages in buffered console contains "installing...AWSSDK" in last operation
- $instanceField = [NuGet.Dialog.PackageManagerWindow].GetField("CurrentInstance", [System.Reflection.BindingFlags]::Static -bor `
- [System.Reflection.BindingFlags]::NonPublic)
- $consoleField = [NuGet.Dialog.PackageManagerWindow].GetField("_smartOutputConsoleProvider", [System.Reflection.BindingFlags]::Instance -bor `
- [System.Reflection.BindingFlags]::NonPublic)
- if ($instanceField -eq $null -or $consoleField -eq $null) { return }
- $instance = $instanceField.GetValue($null)
- if ($instance -eq $null) { return }
- $consoleProvider = $consoleField.GetValue($instance)
- if ($consoleProvider -eq $null) { return }
- $console = $consoleProvider.CreateOutputConsole($false)
- $messagesField = $console.GetType().GetField("_messages", [System.Reflection.BindingFlags]::Instance -bor `
- [System.Reflection.BindingFlags]::NonPublic)
- if ($messagesField -eq $null) { return }
- $messages = $messagesField.GetValue($console)
- if ($messages -eq $null) { return }
- $operations = $messages -split "=============================="
- $lastOperation = $operations | select -last 1
- if ($lastOperation)
- {
- $lastOperation = $lastOperation.ToLower()
- $lines = $lastOperation -split "`r`n"
- $installMatch = $lines | ? { $_.StartsWith("------- installing...awssdk") } | select -first 1
- if ($installMatch)
- {
- $dte2.ItemOperations.Navigate($url) | Out-Null
- }
- }
- }
- }
- catch
- {
- try
- {
- $pmPane = $dte2.ToolWindows.OutputWindow.OutputWindowPanes.Item("Package Manager")
- $selection = $pmPane.TextDocument.Selection
- $selection.StartOfDocument($false)
- $selection.EndOfDocument($true)
- if ($selection.Text.StartsWith("Installing 'awssdk"))
- {
- $dte2.ItemOperations.Navigate($url) | Out-Null
- }
- }
- catch
- {
- # stop potential errors from bubbling up
- # worst case the splash page won't open
- }
- }
- function UpdateCurrentProjectsConfigFile([string]$name)
- {
- $config = $project.ProjectItems | where {$_.Name -eq "Web.config"}
- if ($config -eq $null)
- {
- $config = $project.ProjectItems | where {$_.Name -eq "App.config"}
- if ($config -eq $null)
- {
- return
- }
- }
- $localPath = $config.Properties | where {$_.Name -eq "LocalPath"}
- UpdateConfigFile($localPath.Value, $name)
- }
- function UpdateConfigFile([string]$configFilePath, [string]$name)
- {
- $references = (Select-String $configFilePath -pattern "AWSProfileName").Matches.Count
- If( $references -ne 0)
- {
- Write-Host "AWSProfileName already exists in config file"
- return
- }
- $xml = New-Object xml
- $xml.Load($configFilePath)
- $appSettingNode = $xml.SelectSingleNode("configuration/appSettings/add[@key = 'AWSProfileName']")
-
- Write-Host "Adding AWSProfileName appSetting to " $configFilePath
- $appSettingsNode = $xml.SelectSingleNode("configuration/appSettings")
- if ($appSettingsNode -eq $null)
- {
- $appSettingsNode = $xml.CreateElement("appSettings")
- $xml.DocumentElement.AppendChild($appSettingsNode)
- }
- if ($name -eq "")
- {
- $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")
- $appSettingsNode.AppendChild($comment)
- }
-
- $xml.Save($configFilePath)
- }
- UpdateCurrentProjectsConfigFile ""