【问题标题】:compile ms office interop app from commandline从命令行编译 ms office interop 应用程序
【发布时间】:2009-07-02 19:18:36
【问题描述】:

我如何使用 csc.exe 从命令行成功编译这段代码,就我应该引用哪个 dll 而言。我希望它可以与 Office 2007 和 Office 2003 一起使用。

我使用的是 .Net Framework SDK 2.0。

我得到这个编译错误:

(2,37):错误 CS0234:命名空间“Microsoft.Office”中不存在类型或命名空间名称“Interop”(您是否缺少程序集引用?)

源代码:

using Microsoft.Office.Core;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;

 namespace PPInterop
 {
 class Program
 {
    static void Main(string[] args)
    {
            PowerPoint.Application app = new PowerPoint.Application();
            PowerPoint.Presentations pres = app.Presentations;
            PowerPoint._Presentation file = pres.Open(@"C:\project\JavaTut1.ppt", MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);
            file.SaveCopyAs(@"C:\project\presentation1.jpg", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoTrue);
    }
  }
 }

【问题讨论】:

    标签: c# interop compilation powerpoint csc


    【解决方案1】:

    您需要找到实现您引用的接口的 dll 的路径,然后查看 csc.exe 的命令行参数以了解如何将这些引用添加到您的命令中。

    【讨论】:

      【解决方案2】:

      您需要包含 Microsoft.Office.Interop.PowerPoint,路径应类似于: C:\Program Files\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office12\Microsoft.Office.Interop.PowerPoint.dll for 07 并用 Office11 替换 Office12 for 03 我相信

      【讨论】:

      • 这是一个示例:Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"C:\Program Files\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office12\Microsoft.Office.Interop.PowerPoint.dll" /reference:"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /参考:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" / debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\Test.dll /target:library Test.cs
      猜你喜欢
      • 1970-01-01
      • 2010-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-04
      相关资源
      最近更新 更多