【发布时间】:2014-11-01 11:29:07
【问题描述】:
我正在使用 C# 和 .NET 4.0 框架来开发 WPF 应用程序。我需要执行这样的任务:在桌面上安装我的 WPF 应用程序之前,我需要删除该安装桌面中的一些文件夹。我尝试了以下一个:
文件安装程序.cs
this.BeforeInstall +=new InstallEventHandler(Installer_BeforeInstall);
void Installer_BeforeInstall(object sender, InstallEventArgs e)
{
// Code
}
我在上述方法中用于删除文件夹/目录的任何代码都是在我的 WPF 应用程序安装后执行的,这意味着安装完成了一半。在 WPF 应用程序将安装文件夹保存在我的桌面上之前,我需要删除该文件夹。如何使用 .NET 4.0 在 C# 中执行此操作?
更新:installer.cs
namespace namespace name
{
[RunInstaller(true)]
public partial class Installer : System.Configuration.Install.Installer
{
public Installer()
{
InitializeComponent();
this.AfterInstall += new InstallEventHandler(ServiceInstaller_AfterInstall);
this.BeforeUninstall += new InstallEventHandler(ServiceInstaller_BeforeUninstall);
}
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
}
void ServiceInstaller_AfterInstall(object sender, InstallEventArgs e)
{
//code
}
void ServiceInstaller_BeforeUninstall(object sender, InstallEventArgs e)
{
// Code
}
}
}
【问题讨论】:
-
作为一个建议:使用像 WIX(免费)这样的框架来制作你的安装程序。安装某些东西是一项复杂的任务,尤其是在发生意外情况时。 WiX 需要一些时间来理解,但是非常强大
-
您使用什么来安装应用程序? InstallShield, Wix, ClickOnce, xcopy, ... ??
-
@Mrchief 我正在使用 VS2010 构建解决方案。MSI 文件已生成,我正在使用该 msi 文件进行安装。
-
您有机会发布完整的
installer.cs代码吗? -
我认为您最好的选择是使用纯 msi 解决方案。有一个 removefile 表。使用 orca 执行此操作,请参阅 symantec.com/connect/forums/…
标签: c# .net visual-studio-2010 c#-4.0