调试(逐步完成)一个VS安装项目,你怎么做?
本文关键字:项目 安装 VS 一个 调试 | 更新日期: 2023-09-27 18:06:35
我试图调试我在c# (VS)中创建的安装项目…我的项目目前设置为"调试"而不是"发布",我已将以下代码添加到我的自定义操作区域…
public override void Install(System.Collections.IDictionary stateSaver)
{
if (Debugger.IsAttached == false) Debugger.Launch();
MessageBox.Show("Installing Application...");
//Continue with install process
base.Install(stateSaver);
}
//Code to perform at the time of uninstalling application
public override void Uninstall(System.Collections.IDictionary savedState)
{
if (Debugger.IsAttached == false) Debugger.Launch();
MessageBox.Show("Uninstalling Application...");
//Continue with uninstall process
base.Uninstall(savedState);
}
当我去安装(右键单击安装项目->安装)它按预期工作,我可以使用F11通过每行步骤。当我去卸载(右键单击安装项目->卸载),它不会让我一步通过使用F11或继续使用F5或看到任何智能感知弹出(如变量值等)。虽然我可以点击文件菜单选项来做每一个(调试->继续和调试->进入)。
你知道为什么会这样吗?我怎样才能得到这个功能?
附加问题:是否有可能改变任何代码(如添加消息框),而在运行期间步进安装项目,就像你会与一个正常的程序?
解决方案:在我的情况下,我试图调试我的自定义安装操作install()和Uninstall()。最后,我在自定义动作中添加了以下内容:
if (Debugger.IsAttached == false) Debugger.Launch();
这很简单,下面是它的一个例子…
//Code to perform at the time of installing application
public override void Install(System.Collections.IDictionary stateSaver)
{
if (Debugger.IsAttached == false) Debugger.Launch();
CustomParameters cParams = new CustomParameters();
cParams.Add("InstallPath", this.Context.Parameters["targetdir"]);
cParams.SaveState(stateSaver);
//Continue with install process
base.Install(stateSaver);
}