【问题标题】:visual studio installer does not delete all file in uninstallVisual Studio 安装程序不会删除卸载中的所有文件
【发布时间】:2013-01-08 13:46:22
【问题描述】:

我正在使用 Visual Studio 安装程序。 但是在卸载时 - 从添加删除程序中它不会删除所有文件而是留下一些文件的文件夹,我怎样才能导致卸载删除所有文件?

【问题讨论】:

    标签: visual-studio installation


    【解决方案1】:

    安装程序只删除它安装的文件。安装后创建的文件不会被删除。您必须创建自定义操作来执行清理。

    【讨论】:

    • 处理这个问题的正确方法是我不知道存在哪些文件? - 不同版本的安装程序安装不同的文件。如何删除安装文件夹中的所有文件?
    • 您可以使用自定义操作操作
    【解决方案2】:

    要清理您的软件(删除一些自定义或用户生成的文件),您应该创建一个自定义操作并将其添加到安装程序的卸载部分。

    自定义操作可以是继承自 System.Configuration.Install.Installer 类的类库。

    这是卸载程序自定义操作的示例实现:

    [RunInstaller(true)]
    public partial class CustomUninstaller : System.Configuration.Install.Installer
    {
        public CustomUninstaller()
        {
            InitializeComponent();
        }
    
        public override void Uninstall(IDictionary savedState)
        {
            if (savedState != null)
            {
                base.Uninstall(savedState);
            }
    
            string targetDir = @"C:\Your\Installation\Path";
            string tempDir = Path.Combine(targetDir, "temp");
    
            try
            {
                // delete temp files (you can as well delete all files: "*.*")
                foreach (FileInfo f in new DirectoryInfo(targetDir).GetFiles("*.tmp"))
                {
                    f.Delete();
                }
    
                // delete entire temp folder
                if (Directory.Exists(tempDir))
                {
                    Directory.Delete(tempDir, true);
                }
            }
            catch (Exception ex)
            {
                // TODO: Handle exceptions here
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-11
      • 1970-01-01
      • 2014-12-01
      • 2013-09-21
      • 1970-01-01
      • 2018-03-28
      相关资源
      最近更新 更多