/// <summary>
        /// Updates the current deployment.
        /// </summary>
        /// <param name="deployment">The deployment.</param>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        protected override bool UpdateCurrentDeployment(ApplicationDeployment deployment, ref string message)
        {
            //Call VSTOInstaller Explicitly in "Silent Mode"
            var installerPath = GetInstallerPath();
            if (installerPath == null)
            {
                message = "Cannot resolve VSTO Installer installation path";
                return false;                
            }
            var installerArgs = string.Format(" /S /I {0}", deployment.UpdateLocation.AbsoluteUri);

            var vstoInstallerOutput = new StringBuilder();

            var vstoStartInfo = new ProcessStartInfo(installerPath, installerArgs);
            var returnCode = vstoStartInfo.StartProcess((sender, e) => vstoInstallerOutput.Append((string) e.Data));

            message = vstoInstallerOutput.ToString();
            return returnCode == 0;
        }
Ejemplo n.º 2
0
        private void Uninstall()
        {
            try
            {
                if (SelectedAddin.ManifestExists)
                {
                    var installerPath = VstoClickOnceUpdater.GetInstallerPath();

                    if (installerPath == null)
                    {
                        throw new InvalidOperationException("Cannot find VSTO Installer");
                    }
                    var installerArgs = string.Format(" /U \"{0}\"", SelectedAddin.Manifest);

                    var vstoInstallerOutput = new StringBuilder();

                    var vstoStartInfo = new ProcessStartInfo(installerPath, installerArgs);
                    var returnCode = vstoStartInfo.StartProcess((sender, e) => vstoInstallerOutput.Append(e.Data));

                    var message = vstoInstallerOutput.ToString();

                    if (returnCode != 0)
                    {
                        SelectedAddin.RegistryKey.DeleteKey();
                        MessageBox.Show(string.Format(
                            "Add-in was not installed through VSTOInstaller (probably visual studio instead), {0} was manually removed",
                            SelectedAddin.AddinName), "Success");
                    }
                    else
                    {
                        MessageBox.Show(string.Format("{0} uninstalled", SelectedAddin.AddinName), "Success");
                    }
                }
                else
                {
                    //Manifest doesn't exist, delete registry keys manually
                    SelectedAddin.RegistryKey.DeleteKey();
                    MessageBox.Show(string.Format("{0} uninstalled", SelectedAddin.AddinName), "Success");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error Uninstalling");
                return;
            }

            _addins.Remove(SelectedAddin);
            SelectedAddin = null;
        }