[英]Console Outputs not showing in VSTO Visual Studio 2019
I am doing a tutorial on how to write Add-ins for Outlook(2016).我正在做一个关于如何为 Outlook(2016)编写插件的教程。 I am using Visual Studio 2019 as IDE and C# as Language.
我使用 Visual Studio 2019 作为 IDE,使用 C# 作为语言。 When I run the following code, Outlook opens, nothing else happens.
当我运行以下代码时,Outlook 打开,没有其他任何反应。 I am just trying to figure out the code so I put some outputs inside.
我只是想弄清楚代码,所以我在里面放了一些输出。 However, they are not working and as I got told, "Console.WriteLine" will not work in VSTO.
但是,它们不起作用,正如我被告知的那样,“Console.WriteLine”在 VSTO 中不起作用。 So I use "Debug.WriteLine" in the beginning, just to make sure this method gets executed.
所以我在开始时使用“Debug.WriteLine”,只是为了确保这个方法被执行。
But it is not found in the output.但是在输出中没有找到。 Also not found when I am debugging the application.
在我调试应用程序时也找不到。
I hope you know why this happens and can guide me in the right direction.我希望你知道为什么会发生这种情况,并能指导我朝着正确的方向前进。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using System.Windows.Forms;
using System.Diagnostics;
namespace OutlookAddIn1
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Debug.WriteLine("HELLO WORLD");
// Get the Application object
Outlook.Application application = this.Application;
// Get the Inspector object
Outlook.Inspectors inspectors = application.Inspectors;
// Get the active Inspector object
Outlook.Inspector activeInspector = application.ActiveInspector();
if (activeInspector != null)
{
// Get the title of the active item when the Outlook start.
// MessageBox.Show("Active inspector: " + activeInspector.Caption);
Console.WriteLine("Active Inspector: " + activeInspector.Caption);
}
// Get the Explorer objects
Outlook.Explorers explorers = application.Explorers;
// Get the active Explorer object
Outlook.Explorer activeExplorer = application.ActiveExplorer();
if (activeExplorer != null)
{
// Get the title of the active folder when the Outlook start.
// MessageBox.Show("Active explorer: " + activeExplorer.Caption);
Console.WriteLine("Active explorer: " + activeInspector.Caption);
}
Console.ReadKey();
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region Von VSTO generierter Code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
The Console.WriteLine
method makes sense if you display a console window.如果您显示控制台窗口,则
Console.WriteLine
方法是有意义的。 If not, you may use the Debug.WriteLine
method which writes information about the debug to the trace listeners in the Listeners
collection.如果没有,您可以使用
Debug.WriteLine
方法,该方法将有关调试的信息写入Listeners
集合中的跟踪侦听Listeners
。 By default, the output is written to an instance of DefaultTraceListener .默认情况下,输出被写入DefaultTraceListener 的一个实例。 I'd suggest setting a breakpoint in the code to make sure it is run at all.
我建议在代码中设置一个断点以确保它完全运行。
If you don't get any output from your add-in, Microsoft Office applications can disable VSTO Add-ins that behave unexpectedly.如果您没有从加载项中获得任何输出,Microsoft Office 应用程序可以禁用行为异常的 VSTO 加载项。 If an application does not load your VSTO Add-in when you try to debug it, the application might have hard disabled or soft disabled your VSTO Add-in.
如果应用程序在您尝试调试时未加载您的 VSTO 外接程序,则该应用程序可能已硬禁用或软禁用您的 VSTO 外接程序。
Hard disabling can occur when a VSTO Add-in causes the application to close unexpectedly.当 VSTO 外接程序导致应用程序意外关闭时,可能会发生硬禁用。 It might also occur on your development computer if you stop the debugger while the Startup event handler in your VSTO Add-in is executing.
如果您在 VSTO 外接程序中的启动事件处理程序正在执行时停止调试器,也可能会在您的开发计算机上发生这种情况。
Soft disabling can occur when a VSTO Add-in produces an error that does not cause the application to unexpectedly close.当 VSTO 外接程序产生不会导致应用程序意外关闭的错误时,可能会发生软禁用。 For example, an application might soft disable a VSTO Add-in if it throws an unhandled exception while the Startup event handler is executing.
例如,如果应用程序在启动事件处理程序正在执行时抛出未处理的异常,它可能会软禁用 VSTO 外接程序。
When you re-enable a soft-disabled VSTO Add-in, the application immediately attempts to load the VSTO Add-in.当您重新启用软禁用的 VSTO 插件时,应用程序会立即尝试加载 VSTO 插件。 If the problem that initially caused the application to soft disable the VSTO Add-in has not been fixed, the application will soft disable the VSTO Add-in again.
如果最初导致应用程序软禁用 VSTO 加载项的问题尚未解决,应用程序将再次软禁用 VSTO 加载项。
Read more about that in the How to: Re-enable a VSTO Add-in that has been disabled article.在如何:重新启用已被禁用的 VSTO 加载项一文中阅读更多相关信息。
We have developed a Word Add-In to allow users to edit Chemistry inside Microsoft Word.我们开发了一个 Word 插件,允许用户在 Microsoft Word 中编辑化学。 In this, we have plenty of Debug.WriteLine statements.
在这里,我们有很多 Debug.WriteLine 语句。
When running outside of the Visual Studio IDE we have to use the excellent System Internals Debug Viewer to view the debug output在 Visual Studio IDE 之外运行时,我们必须使用出色的System Internals Debug Viewer来查看调试输出
When running inside the Visual Studio IDE we have to set the startup project as the VSTO being developed and the debugger to start an external program in our case MS Word as shown below在 Visual Studio IDE 中运行时,我们必须将启动项目设置为正在开发的 VSTO 和调试器来启动我们的案例 MS Word 中的外部程序,如下所示
You should obviously set this to the version of Outlook which you have installed
您显然应该将其设置为您已安装的 Outlook 版本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.