public InstalledExtension InstallSampleExtension()
        {
            // Identifiers of the extension to install
            string publisherName = "ms-samples";
            string extensionName = "samples-contributions-guide";

            // Get the client
            VssConnection connection = Context.Connection;
            ExtensionManagementHttpClient extensionManagementClient = connection.GetClient <ExtensionManagementHttpClient>();

            InstalledExtension extension = null;

            // Try to install the extension
            try
            {
                Context.Log("Trying to install extension {0}.{1}...", publisherName, extensionName);

                extension = extensionManagementClient.InstallExtensionByNameAsync(publisherName, extensionName).Result;

                Context.Log("Extension installed successfully!");
            }
            catch (Exception ex)
            {
                // Unable to install the extension
                Context.Log("Unable to install the extension. Error: {0}", ex.Message);
            }

            if (extension != null)
            {
                LogExtension(extension);
            }

            return(extension);
        }
 protected void LogExtension(InstalledExtension extension)
 {
     Context.Log(" {0}.{1}{2}: {3} by {4}",
                 extension.PublisherName,
                 extension.ExtensionName,
                 (extension.Flags.HasFlag(ExtensionFlags.BuiltIn) ? "*" : ""),
                 extension.ExtensionDisplayName,
                 extension.PublisherDisplayName);
 }
        public InstalledExtension GetInstalledSampleExtension()
        {
            // Identifiers of the extension to uninstall
            string publisherName = "ms-samples";
            string extensionName = "samples-contributions-guide";

            // Get the client
            VssConnection connection = Context.Connection;
            ExtensionManagementHttpClient extensionManagementClient = connection.GetClient <ExtensionManagementHttpClient>();

            // Try to get the extension
            try
            {
                InstalledExtension extension = extensionManagementClient.GetInstalledExtensionByNameAsync(publisherName, extensionName).Result;
                LogExtension(extension);
                return(extension);
            }
            catch (Exception ex)
            {
                Context.Log("Unable to get the extension: {0}", ex.Message);
                return(null);
            }
        }