【问题标题】:Can't Debug Application-Level Add-in for Outlook无法调试 Outlook 的应用程序级加载项
【发布时间】:2012-09-30 21:39:40
【问题描述】:

这是我第一次使用 .NET 为 Outlook 创建应用程序级插件。通过使用教程,我写下了一些代码并成功构建,但我无法调试代码。调试时会显示一个警告框:

您无法运行或调试此项目,因为未安装所需版本的 Microsoft 应用程序。

我正在使用 Visual Studio 2010MS Office 2007。为了调试代码我应该怎么做?我可以对代码进行任何更改以便调试吗?

这里是代码

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 Microsoft.Office.Interop.Outlook;
namespace OutlookAddIn1
{

    public partial class ThisAddIn
    {
        Outlook.Inspectors inspectors;
        event InspectorsEvents_NewInspectorEventHandler NewInspector;


        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            inspectors = this.Application.Inspectors;
            inspectors.NewInspector +=
            new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector); 
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {

        }
        void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
        {
            Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
            if (mailItem != null)
            {
                if (mailItem.EntryID == null)
                {
                    mailItem.Subject = "This text was added by using code";
                    mailItem.Body = "This text was added by using code";
                }

            }
        }
        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

        #endregion
    }
}

【问题讨论】:

    标签: c# outlook vsto ms-office outlook-addin


    【解决方案1】:

    问题不在于您的代码 - 它是您的项目文件和您安装的 MS Office 版本的错误配置。见related SO post regarding editing DebugInfoExeName in the csproj to match the proper Office version

    Office Version | Version Number
    ---------------+-----------------
        2007       |   12.0
        2010       |   14.0
        2013       |   15.0
        2016       |   16.0
    

    对于MS Office 2007,您的项目文件DebugInfoExeName 应该是:

    DebugInfoExeName="#Software\Microsoft\Office\12.0\Outlook\InstallRoot \Path#outlook.exe"

    【讨论】:

    • 对于 MS Office 2016,版本号为“16.0”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-05
    • 1970-01-01
    • 2021-06-15
    • 2019-10-29
    • 2020-02-18
    • 2019-03-22
    • 1970-01-01
    相关资源
    最近更新 更多