显示来自 C# AfterInstall 事件的错误消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/343678/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 23:56:37  来源:igfitidea点击:

Displaying Error Message from C# AfterInstall Event

c#windowsinstaller

提问by

Can someone please tell me how to display error message in C# during execution of AfterInstallEvent?

有人可以告诉我如何在执行 AfterInstallEvent 期间在 C# 中显示错误消息吗?

My project uses the Microsoft set-up and deployment project and then I have created a class that is called when the AfterInstall event is fired.

我的项目使用 Microsoft 设置和部署项目,然后我创建了一个在触发 AfterInstall 事件时调用的类。

MessageBox.Show(); doesn't work..."The name 'MessageBox' does not appear in the current context".

MessageBox.Show(); 不起作用...“名称‘MessageBox’未出现在当前上下文中”。

If it was that simple, I wouldn't be asking!?

要是这么简单,我就不会问了!?

回答by

The real solution is to use scope. Something like this: global::System.Windows.Forms.MessageBox.Show(ex,"Error",MessageBoxButtons.OK, MessageBoxIcon.Error);

真正的解决方案是使用范围。像这样: global::System.Windows.Forms.MessageBox.Show(ex,"Error",MessageBoxButtons.OK, MessageBoxIcon.Error);

Cheers

干杯

回答by

This is very old but I'll answer anyway:

这已经很老了,但我还是会回答:

It's just a missing reference.

这只是一个缺失的参考。

Add a reference to System.Windows.Formsto the project containing the class. Also add "using System.Windows.Forms;"to the top of your class file.

向包含该类的项目添加对System.Windows.Forms的引用。还要添加“使用 System.Windows.Forms;” 到你的类文件的顶部。

As far as I know there shouldn't be any issues with displaying message boxes from a custom install action.

据我所知,显示来自自定义安装操作的消息框应该没有任何问题。