2010-10-03 51 views
0

我正面臨一個好奇的問題: 我想用Visual Studio 2008使用共享的加載項模板爲Outlook 2002構建一個加載項。 我想在OnStartUpComplete方法中使用一個簡單的hello world。 這對我的開發機器來說是完美的工作,但對Outlook 2002來說並不是一臺乾淨的機器。 我使用生成的安裝項目來安裝加載項。 啓動Outlook後加載行爲從3改回到2,出現異常或其他錯誤。 我需要做些什麼才能使加載項在開發機器之外工作?Outlook 2002 C#COM插件與VS2008構建不啓動

非常感謝,

邁克爾

回答

0

我相信你是一個背鎖政策的受害者。 向註冊表添加一個旁路密鑰,然後它可以工作。現代辦公室版本或vsto在安裝時創建密鑰。效果是:現在也安裝一個現代化的辦公室,現在adddin也加載到舊辦公室。請看看來自NetOffice http://netoffice.codeplex.com

public static void RegisterFunction(Type type) 
{ 
      try 
      { 
       // add codebase value 
       Assembly thisAssembly = Assembly.GetAssembly(typeof(ExampleClassicAddin)); 
       RegistryKey key = Registry.ClassesRoot.CreateSubKey("CLSID\\{" + type.GUID.ToString().ToUpper() + "}\\InprocServer32\\1.0.0.0"); 
       key.SetValue("CodeBase", thisAssembly.CodeBase); 
       key.Close(); 

       key = Registry.ClassesRoot.CreateSubKey("CLSID\\{" + type.GUID.ToString().ToUpper() + "}\\InprocServer32"); 
       key.SetValue("CodeBase", thisAssembly.CodeBase); 
       key.Close(); 

       // add bypass key 
       // http://support.microsoft.com/kb/948461 
       key = Registry.ClassesRoot.CreateSubKey("Interface\\{000C0601-0000-0000-C000-000000000046}"); 
       string defaultValue = key.GetValue("") as string; 
       if (null == defaultValue) 
        key.SetValue("", "Office .NET Framework Lockback Bypass Key"); 
       key.Close(); 

       // add addin key 
       Registry.ClassesRoot.CreateSubKey(@"CLSID\{" + type.GUID.ToString().ToUpper() + @"}\Programmable"); 
       Registry.CurrentUser.CreateSubKey(_addinRegistryKey + _prodId); 
       RegistryKey rk = Registry.CurrentUser.OpenSubKey(_addinRegistryKey + _prodId, true); 
       rk.SetValue("LoadBehavior", Convert.ToInt32(3)); 
       rk.SetValue("FriendlyName", _addinName); 
       rk.SetValue("Description", "NetOffice COMAddinExample with classic UI"); 
       rk.Close(); 
      } 
      catch (Exception ex) 
      { 
       string details = string.Format("{1}{1}Details:{1}{1}{0}", ex.Message, Environment.NewLine); 
       MessageBox.Show("An error occured." + details, "Register " + _addinName, MessageBoxButtons.OK, MessageBoxIcon.Error); 
      } 
} 
採取

代碼段