2013-01-08 62 views

回答

0

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

+0

什么来处理,这是我不知道是哪个文件存在的正确方法? - 不同版本的安装程序安装不同的文件。如何删除安装文件夹中的所有文件? – user271077

+0

您可以使用自定义操作操作 – Ciprian

0

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

自定义操作可以是继承自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 
     } 
    } 
} 
相关问题