2012-10-10 48 views
7

這是我第一次使用.NET爲Outlook創建應用程序級加載項。通過使用教程我寫下了一些代碼,它已成功構建,但我無法調試代碼。在調試警告框時會顯示:無法調試Outlook的應用程序級加載項

由於未安裝所需版本的Microsoft應用程序,因此無法運行或調試此項目。

我使用Visual Studio 2010中MS 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 
    } 
} 

回答

18

問題不在於你的代碼 - 這是您的項目文件和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 = 「#軟件\微軟\辦公室\ 12.0 \ Outlook中\ InstallRoot \路徑#OUTLOOK.EXE」

+1

對於MS Office 2016,版本號爲「16.0」。 –