csc编码代码时如何引用‘COM’类的dll

exinke 2015-09-28 08:32:15
我要编译源代码,调用一些自己写的dll,以及现有产品提供的COM类的dll。在运行命令时提示错误
csc /target:library /out:"E:\UCCAddon.dll" "E:\*.cs" /reference:"e:\baseforms.dll";"e:\publicapi.dll";"C:\Program Files (x86)\SAP\SAP Business One DI API\DI API 90\SAPbobsCOM90.dll"

----------------------------------------------------运行命令------------------------
E:\>csc /target:library /out:"E:\UCCAddon.dll" "E:\*.cs" /reference:"e:\basefor
ms.dll";"e:\publicapi.dll";"C:\Program Files (x86)\SAP\SAP Business One DI API\D
I API 90\SAPbobsCOM90.dll"
Microsoft (R) Visual C# Compiler version 4.6.0081.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.

This compiler is provided as part of the Microsoft (R) .NET Framework, but only
supports language versions up to C# 5, which is no longer the latest version. Fo
r compilers that support newer versions of the C# programming language, see http
://go.microsoft.com/fwlink/?LinkID=533240

fatal error CS0009: 未能打开元数据文件“c:\Program Files (x86)\SAP\SAP Business
One DI API\DI API 90\SAPbobsCOM90.dll”--“试图加载格式不正确的程序。 ”



求高手帮助
...全文
158 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Forty2 2015-09-28
  • 打赏
  • 举报
回复
当你用VS的时候,VisualStudio项目会帮你把一个TypeLib,转换为一个Com互操作的dll,并引用生成的Com互操作的dll。 如果你不怕麻烦要自己做(或者喜欢探究原理),可以分两步走:一、用tlbimp.exe来生成dll(VisualStudio也用这个工具),二、再用csc编译
tlbimp.exe "C:\Program Files (x86)\SAP\SAP Business One DI API\DI API 90\SAPbobsCOM90.dll" /out:"SAPbobsCOM90.Interop.dll"
csc /target:library /out:"E:\UCCAddon.dll"  "E:\*.cs" /reference:"e:\baseforms.dll";"e:\publicapi.dll";"SAPbobsCOM90.Interop.dll"
  • 打赏
  • 举报
回复
为什么不用vs编译呢?这个csc指令用起来太麻烦了

110,548

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧