Ejemplo n.º 1
0
        /// <summary>
        /// Applies one or more patches to products that are eligible to receive the patch.
        /// For each product listed by the patch package as eligible to receive the patch, ApplyPatch invokes
        /// an installation and sets the PATCH property to the path of the patch package.
        /// </summary>
        /// <param name="patchPackages">The set of patch packages to be applied.
        /// Each item is the full path to an MSP file.</param>
        /// <param name="productCode">Provides the ProductCode of the product being patched. If this parameter
        /// is null, the patches are applied to all products that are eligible to receive these patches.</param>
        /// <param name="commandLine">optional command line property settings</param>
        /// <remarks><p>
        /// Win32 MSI API:
        /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msiapplymultiplepatches.asp">MsiApplyMultiplePatches</a>
        /// </p></remarks>
        public static void ApplyMultiplePatches(
            IList <string> patchPackages, string productCode, string commandLine)
        {
            if (patchPackages == null || patchPackages.Count == 0)
            {
                throw new ArgumentNullException("patchPackages");
            }

            StringBuilder patchList = new StringBuilder();

            foreach (string patch in patchPackages)
            {
                if (patch != null)
                {
                    if (patchList.Length != 0)
                    {
                        patchList.Append(';');
                    }

                    patchList.Append(patch);
                }
            }

            if (patchList.Length == 0)
            {
                throw new ArgumentNullException("patchPackages");
            }

            uint ret = NativeMethods.MsiApplyMultiplePatches(patchList.ToString(), productCode, commandLine);

            Installer.CheckInstallResult(ret);
        }