2012-10-10 11 views
7

Questa è la prima volta che utilizzo .NET per creare un componente aggiuntivo a livello di applicazione per Outlook. Usando un tutorial ho scritto un po 'di codice ed è stato compilato con successo, ma non ho potuto eseguire il debug del codice. Durante il debug di una finestra di avviso viene visualizzato:Impossibile eseguire il debug del componente aggiuntivo a livello di applicazione per Outlook

Non è possibile eseguire o eseguire il debug di questo progetto perché la versione richiesta dell'applicazione Microsoft non è installata.

Sto usando Visual Studio 2010 e MS Office 2007. Per eseguire il debug del codice, cosa devo fare? Posso apportare modifiche al codice in modo da poter eseguire il debug.

Ecco il codice

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 
    } 
} 

risposta

18

Il problema non è il codice - si tratta di un'errata configurazione del file di progetto e quale versione di MS Office è stato installato. Vedi 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 

Per MS Office 2007, il file di progetto DebugInfoExeName dovrebbe essere:

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

+1

Per MS Office 2016, il numero di versione è "16,0". –

Problemi correlati