Why is my Uninstall method not called from the msi

2019-07-04 11:34发布

I am writing an installer for my web app and I struggle with the uninstaller part. Despite the fact that I created a custom action on Uninstall in my Application Setup Project, the InstallerClass is set to true, the method:

public override void Uninstall(IDictionary savedState)
    {
        //MessageBox.Show("Attach debugger!", "Viper.Setup");
        Cleanup();
        base.Uninstall(savedState);
    }

on the installer class doesn't seem to be called. Any ideas what could be the reason?

EDIT: I also noticed that it not only doesn't run the Installer, but also doesn't delete my main dll file. To make it worse, when I install a new version after uninstalling the previous one, this dll is still the old one (even though installation and uninstallation were successful)

7条回答
地球回转人心会变
2楼-- · 2019-07-04 11:46

I solved this by setting the 'InstallerClass' property of my custom action to False.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-07-04 12:02

Did you include the output of your installer code in the Code Actions tab of the installer?

If that's not it...

I ran into a similar problem in the past and found I needed all 4 methods defined or the uninstall would not run. Add your code to the template below:

[RunInstaller(true)]
public class MyInstaller: Installer
{
    public override void Install(IDictionary stateSaver)
    {
        base.Install(stateSaver);
    }

    public override void Commit(IDictionary savedState)
    {
        base.Commit(savedState);
    }

    public override void Rollback(IDictionary savedState)
    {
        base.Rollback(savedState);
    }

    public override void Uninstall(IDictionary savedState)
    {
        base.Uninstall(savedState);
    }
}

Hope this helps!

查看更多
唯我独甜
4楼-- · 2019-07-04 12:03

I stopped using these rubbish msi's and created a zip + cmd script instead. Strongly recommended, took me 10 times less to set up and actually works.

查看更多
Lonely孤独者°
5楼-- · 2019-07-04 12:05

I've created an installer project for an wpf application, similar to your setup, see here, the problem described there is less important for this topic.

Nevertheless, I encountered the same problem as you described. I've placed that installer class in the visual studio installer project which prevents the class from execution. Everything worked well whenever the installer class was put into the main application.

查看更多
家丑人穷心不美
6楼-- · 2019-07-04 12:09

I had the same issue here... hurt my head to find out why!!! It turns out though that my install project had the Primary Output of the service set to the "Release", while i was making alterations in the project to the Installer in "Debug". The moment I set them to be the same, my MessageBoxes popped up to show the code was being executed...

.. you can update your project to a much neater solution now :)

查看更多
7楼-- · 2019-07-04 12:10

I don't Know actually why your override uninstall not working . But whenever i face this issue i make a log of the uninstall process . And according to that you can easily check where the problem resides ! Here is the method to make a log by installer class.

 private string logFilePath = "C:\\SetupLog.txt";    
 public void Log(string str)
    {
        StreamWriter Tex;
        try
        {
            Tex = File.AppendText(this.logFilePath);
            Tex.WriteLine(DateTime.Now.ToString() + " " + str);
            Tex.Close();
        }
        catch
        { }
    }

and call this method in Override function like ->

 public override void Uninstall(IDictionary savedState)
    {
       try 
          {
             base.Uninstall(savedState);
             Log("Omg :O it works !");    
           }
      catch(Exception ex)
           {
             Log(ex.Message.ToString());
           }     
    }

At lastly Windows msi ...is not so bad ..Just dont call it rubbish Plz ..:)

查看更多
登录 后发表回答