Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何获取Powershell Azure安装程序的ID_C#_Web Platform Installer - Fatal编程技术网

C# 如何获取Powershell Azure安装程序的ID

C# 如何获取Powershell Azure安装程序的ID,c#,web-platform-installer,C#,Web Platform Installer,我找到了代码,它从Web平台安装程序下载并安装了一些程序。它已经成功运行,但我需要下载并安装Azure PowerShell而不是此软件。那么,如何更改代码(或者如何获取powershell azure的id) 使用系统; 使用System.Collections.Generic; 使用Microsoft.Web.PlatformInstaller; 命名空间CustomProductInstaller { 班级计划 { 受保护的只读静态字符串MainXml=”https://go.micros

我找到了代码,它从Web平台安装程序下载并安装了一些程序。它已经成功运行,但我需要下载并安装Azure PowerShell而不是此软件。那么,如何更改代码(或者如何获取powershell azure的id)

使用系统;
使用System.Collections.Generic;
使用Microsoft.Web.PlatformInstaller;
命名空间CustomProductInstaller
{
班级计划
{
受保护的只读静态字符串MainXml=”https://go.microsoft.com/fwlink/?LinkId=158722";
受保护的只读静态字符串CustomXml=”http://blogs.iis.net/blogs/kateroh/SIR/SIRWebPIFeed.xml";
受保护的只读静态字符串CustomProductId=“AppGallerySIRBinaries”;//需要在此处更改为ID Azure PowerShell
受保护的只读静态字符串CustomAppId=“AppGallerySIRApp”;//需要在此处更改为ID Azure PowerShell
私有静态bool\u installCompleted=false;
静态void Main(字符串[]参数)
{
ProductManager ProductManager=新的ProductManager();
//1.加载主要产品提要
productManager.Load
(
新Uri(MainXml),//主提要的位置
false,//加载所有体系结构和平台的产品
true//加载附件(例如WebApplicationList.xml)
);
//2.加载自定义提要
LoadExternalFile(新Uri(CustomXml));
//3.按产品Id查找自定义产品
Product customProduct=productManager.GetProduct(CustomProductId);
Product customApp=productManager.GetProduct(CustomAppId);
//4.查找要安装的所有产品(自定义产品+其依赖项)
List productsToInstall=new List();
AddProductWithDependencies(customProduct、productsToInstall);
AddProductWithDependencies(customApp、productsToInstall);
//5.选择正确的安装程序-对于所选语言,如果没有,请使用英语
列表安装程序使用=新建列表();
安装程序的语言=productManager.GetLanguage(“fr”);
语言英语=productManager.GetLanguage(“en”);
foreach(产品安装在产品安装中)
{
Installer currentInstaller=productToInstall.GetInstaller(Installer的语言);
如果(currentInstaller==null)
{
currentInstaller=productToInstall.GetInstaller(英语);
}
InstallerUse.Add(当前安装程序);
}
//6.准备安装人员
InstallManager InstallManager=新的InstallManager();
installManager.Load(InstallerUse);
//7.注册安装事件
installManager.InstallerStatusUpdated+=新事件处理程序(installManager\u InstallerStatusUpdated);
installManager.InstallCompleted+=新的事件处理程序(installManager\u InstallCompleted);
foreach(InstallerContext InstallerContext在installManager.InstallerContext中)
{
字符串失败原因;
installManager.DownloadInstallerFile(installerContext,out failureReason);
}
//8.先安装产品
installManager.StartInstallation();
而(!\u安装完成);
_installCompleted=false;
//9.此时ProductManager中的所有产品都已下载,因此我们可以在应用程序上设置参数
//注意:在下载应用程序之前,不能设置应用程序参数
//在这种情况下,Web部署包的语言并不重要,因为它不会显示在UI中
安装程序appInstaller=customApp.GetInstaller(英语);
foreach(DeclaredParameter DeclaredParameter在appInstaller.MSDeployPackage.DeclaredParameters中)
{
//设置没有默认值的参数值
if(string.IsNullOrEmpty(declaredParameter.DefaultValue))
{
appInstaller.MSDeployPackage.SetParameters[declaredParameter.Name]=“新值”;
}
}
//10.然后安装应用程序(因为应用程序可能具有产品依赖性,但不具有产品依赖性)
installManager.StartApplicationInstallation();
而(!\u安装完成);
Console.ReadKey();
}
私有静态void AddProductWithDependencies(产品产品,列出要安装的产品)
{
//避免重复
如果(!productsToInstall.Contains(产品))
{
productsToInstall.Add(产品);
}
//GetMissingDependencies将检查产品是否未安装任何依赖项
//和尚未添加到安装列表(productsToInstall)
ICollection missingDependencies=product.GetMissingDependencies(productsToInstall);
if(缺少依赖项!=null)
{
foreach(missingDependencies中的产品依赖项)
{
添加ProductWithDependencies(dependency,productsToInstall);
}
}
}
私有静态void InstallManager\u InstallerStatusUpdate(对象发送方,InstallStatusEventArgs e)
{
控制台。写入线(如安装
    using System;
    using System.Collections.Generic;
    using Microsoft.Web.PlatformInstaller;

    namespace CustomProductInstaller
    {
        class Program
        {
            protected readonly static string MainXml = "https://go.microsoft.com/fwlink/?LinkId=158722";
            protected readonly static string CustomXml = "http://blogs.iis.net/blogs/kateroh/SIR/SIRWebPIFeed.xml";

            protected readonly static string CustomProductId = "AppGallerySIRBinaries";//Need change here to ID Azure PowerShell
            protected readonly static string CustomAppId = "AppGallerySIRApp";//Need change here to ID Azure PowerShell

            private static bool _installCompleted = false;

            static void Main(string[] args)
            {
                ProductManager productManager = new ProductManager();

                // 1. Load main product feeds
                productManager.Load
                    (
                        new Uri(MainXml), // location of the main feed 
                        false,            // load products for all architectures and platforms
                        true              // load enclosures (eg WebApplicationList.xml)
                    );

                // 2. Load custom feed
                productManager.LoadExternalFile(new Uri(CustomXml));

                // 3. Find the custom product by product Id
                Product customProduct = productManager.GetProduct(CustomProductId);
                Product customApp = productManager.GetProduct(CustomAppId);

                // 4. Find all products to install (custom product + its dependencies)
                List<Product> productsToInstall = new List<Product>();
                AddProductWithDependencies(customProduct, productsToInstall);
                AddProductWithDependencies(customApp, productsToInstall);

                // 5. Pick the right installers - for the chosen language, if such is not available, fall back to English
                List<Installer> installersToUse = new List<Installer>();
                Language languageOfInstallers = productManager.GetLanguage("fr");
                Language english = productManager.GetLanguage("en");

                foreach (Product productToInstall in productsToInstall)
                {
                    Installer currentInstaller = productToInstall.GetInstaller(languageOfInstallers);
                    if (currentInstaller == null)
                    {
                        currentInstaller = productToInstall.GetInstaller(english); ;
                    }
                    installersToUse.Add(currentInstaller);
                }

                // 6. Prepare installers
                InstallManager installManager = new InstallManager();
                installManager.Load(installersToUse);

                // 7. Sign up for installation events
                installManager.InstallerStatusUpdated += new EventHandler<InstallStatusEventArgs>(InstallManager_InstallerStatusUpdated);
                installManager.InstallCompleted += new EventHandler<EventArgs>(InstallManager_InstallCompleted);

                foreach (InstallerContext installerContext in installManager.InstallerContexts)
                {
                    string failureReason;
                    installManager.DownloadInstallerFile(installerContext, out failureReason);
                }

                // 8. Install products first
                installManager.StartInstallation();
                while (!_installCompleted) ;
                _installCompleted = false;

                // 9. At this point all products in ProductManager are downloaded, so we can set parameters on the application
                // NOTE: you cannot set application parameters, before it is downloaded
                // in this case, the language of the Web Deploy package does not matter, since it is not displayed in the UI
                Installer appInstaller = customApp.GetInstaller(english);
                foreach (DeclaredParameter declaredParameter in appInstaller.MSDeployPackage.DeclaredParameters)
                {
                    // set values of parameters that do not have default values
                    if (string.IsNullOrEmpty(declaredParameter.DefaultValue))
                    {
                        appInstaller.MSDeployPackage.SetParameters[declaredParameter.Name] = "New Value";
                    }
                }

                // 10. Then install applications (because application might have product dependencies, but not vice versa)
                installManager.StartApplicationInstallation();
                while (!_installCompleted) ;

                Console.ReadKey();
            }

            private static void AddProductWithDependencies(Product product, List<Product> productsToInstall)
            {
                // avoid duplicates 
                if (!productsToInstall.Contains(product))
                {
                    productsToInstall.Add(product);
                }

                // GetMissingDependencies will check whether any dependencies are not installed for the product
                // AND are not already added to the install list (productsToInstall)
                ICollection<Product> missingDependencies = product.GetMissingDependencies(productsToInstall);
                if (missingDependencies != null)
                {
                    foreach (Product dependency in missingDependencies)
                    {
                        AddProductWithDependencies(dependency, productsToInstall);
                    }
                }
            }

            private static void InstallManager_InstallerStatusUpdated(object sender, InstallStatusEventArgs e)
            {
                Console.WriteLine(e.InstallerContext.ProductName + ": " +
                                  e.InstallerContext.InstallationState + ". " +
                                  e.InstallerContext.ReturnCode.DetailedInformation +
                                  "Progress: " + e.ProgressValue.ToString());
            }

            private static void InstallManager_InstallCompleted(object sender, EventArgs e)
            {
                Console.WriteLine("Installation completed");
                _installCompleted = true;
            }
        }
    }