65.9K
CodeProject 正在变化。 阅读更多。
Home

在 Vista + 2007 Office 下使用 VSTO SE 开发 Outlook 2003 插件

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.62/5 (7投票s)

2007 年 4 月 20 日

CPOL
viewsIcon

50083

如何在 Vista + 2007 Office 下编译和调试 2003 VSTO 插件。

引言

如果你想知道如何在配置为 Vista+Office 2007 的计算机上编译和调试 VSTO SE Outlook 2003 插件,请阅读本文。

步骤

在同一台计算机上安装 Office 2003 PIA 和 Office 2007 PIA

  1. 以试用模式安装 Office 2003
  2. 安装 Office 2003 PIA(我们需要先安装 2003 PIA)
  3. 卸载 Office 2003
  4. 安装 Office 2007
  5. 在 Visual Studio 项目中创建 2003 插件

    为了“无错误”编译,将 2003 COM 引用更改为 .csproj 文件中的 2003 PIA

  6. 在文本编辑器中打开项目文件并找到以下片段

    <!--
    This section specifies COM References for the project 
    (managed assemblies that wrap unmanaged typelibs (tlb)). 
    This is the equivalent of choosing "Add Reference->Com Reference" 
    in the IDE.
    -->
    <ItemGroup>
        <COMReference Include="Microsoft.Office.Core">
            <Guid>{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}</Guid>
            <VersionMajor>2</VersionMajor>
            <VersionMinor>3</VersionMinor>
            <WrapperTool>primary</WrapperTool>
        </COMReference>
        <COMReference Include="Outlook">
            <Guid>{00062FFF-0000-0000-C000-000000000046}</Guid>
            <VersionMajor>9</VersionMajor>
            <VersionMinor>2</VersionMinor>
            <WrapperTool>primary</WrapperTool>
        </COMReference>
        <COMReference Include="stdole">
            <Guid>{00020430-0000-0000-C000-000000000046}</Guid>
            <VersionMajor>2</VersionMajor>
            <VersionMinor>0</VersionMinor>
            <Lcid>0</Lcid>
            <WrapperTool>primary</WrapperTool>
            <Isolated>False</Isolated>
        </COMReference>
    </ItemGroup>
    

  7. 将找到的片段替换为

    <!--
    This section specifies COM References for the project 
    (managed assemblies that wrap unmanaged typelibs (tlb)). 
    This is the equivalent of choosing "Add Reference->Com Reference" 
    in the IDE.
    -->
    <ItemGroup>
        <Reference Include="Microsoft.Office.Interop.Outlook, 
            Version=11.0.0.0, Culture=neutral, 
            PublicKeyToken=71e9bce111e9429c" />
        <Reference Include="Office, Version=11.0.0.0, 
            Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
        <Reference Include="stdole, Version=7.0.3300.0, 
            Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
        <SpecificVersion>False</SpecificVersion>
        </Reference>
    </ItemGroup>
    

  8. 保存后,我们就拥有一个 2003 插件,可以在 Vista+2007 Office 下编译,并且可以在 2003 Office 下运行。
    注意:小心,不要为 Office 和 Outlook DLL 设置 <SpecificVersion>False</SpecificVersion>,因为如果设置了,你的插件将无法在 2003 Office 下运行。

    启用调试功能

  9. 现在一切都很好,但你无法在 2007 Office 下调试 2003 插件。因此,为了启用调试功能,你需要更改项目文件中的 <ProjectExtensions> 标签内的代码,替换为 Outlook 2007 插件项目中的代码片段。

    <!-- 
    This section defines VSTO properties that describe 
    the host-changable project properties. 
    --> 
    <ProjectExtensions> 
      <VisualStudio> 
        <FlavorProperties GUID="{BAA0C2D2-18E2-41B9-852F-F413020CAA33}"> 
          <ProjectProperties HostName="Outlook" 
        HostPackage="{D53BAEDE-5B63-42BE-8267-3DED11EDC582}" 
        ApplicationType="Outlook" Language="cs" TemplatesPath="" 
        DebugInfoExeName=
       "#Software\Microsoft\Office\12.0\Outlook\InstallRoot\Path#Outlook.exe" 
        AddItemTemplatesGuid="{147FB6A7-F239-4523-AE65-B6A4E49B361F}" /> 
            <Host Name="Outlook" 
            GeneratedCodeNamespace="OutlookAddIn3" IconIndex="0"> 
            <HostItem Name="ThisAddIn" Code="ThisAddIn.cs" 
            CanonicalName="ThisAddIn" CanActivate="false" 
            IconIndex="1" Blueprint="ThisAddIn.Designer.xml" 
            GeneratedCode="ThisAddIn.Designer.cs" /> 
            </Host> 
        <ProjectClient> 
          <VSTO_CompatibleProducts ErrorProduct=
          "This project requires Microsoft Office Outlook 2007, 
          but this application is not installed." 
          ErrorPIA="This project references the primary interop assembly 
          for Microsoft Office Outlook 2007, but this primary interop 
          assembly is not installed."> 
          <Product Code="{XX12XXXX-XXXX-XXXX-X000-X000000FF1CE}" 
          Feature="OUTLOOKFiles" PIAFeature="Outlook_PIA" /> 
          </VSTO_CompatibleProducts> 
          </ProjectClient> 
        </FlavorProperties> 
      </VisualStudio> 
    </ProjectExtensions>
    

© . All rights reserved.