在 Visual Studio 中抑制 tlbimp 警告
在 Visual Studio C# 项目中,可以添加对 COM 库的引用。 然后,Visual Studio 将使用 tlbimp.exe 来构建项目时生成互操作程序集。 .csproj 文件中的引用如下所示:
<ItemGroup>
<COMReference Include="TDAPIOLELib">
<Guid>{F645BD06-E1B4-4E6A-82FB-E97D027FD456}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
</COMReference>
</ItemGroup>
但是,我在此处导入的 3rdparty 类型库会导致 tlbimp 发出一些警告。 如何在 Visual Studio 中抑制这些警告? 我尝试将包装工具更改为
<WrapperTool>tlbimp /silent</WrapperTool>
但这会导致视觉工作室抱怨
出现错误 遇到阻止引用的情况 加载“TDAPIOLELib”。 这 包装工具“tlbimp /silent”不是 有效的包装工具。
In a visual studio C# project, it is possible to add references to COM libraries. Visual Studio will then use tlbimp.exe to generate the interop assembly when building the project. The reference looks like this in the .csproj file:
<ItemGroup>
<COMReference Include="TDAPIOLELib">
<Guid>{F645BD06-E1B4-4E6A-82FB-E97D027FD456}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
</COMReference>
</ItemGroup>
However, the 3rdparty type library which I am importing here causes tlbimp to emit some warnings. How do I suppress these warnings in visual studio? I tried to change the wrapper tool to
<WrapperTool>tlbimp /silent</WrapperTool>
but that causes visual studio to complain with
An error has been
encountered that prevents reference
'TDAPIOLELib' from loading. The
wrapper tool 'tlbimp /silent' is not a
valid wrapper tool.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除非 COM 库不断更改其 COM 接口,否则您可以运行一次 typelib 导入程序,然后从那时起在项目中引用互操作程序集。 如果您有 reg free COM,只需将 COM 库复制到您的构建输出文件夹中即可。
unless the COM library is constantly changing it's COM interfaces you could run the typelib importer once and then refer to the interop assembly in your project from then on. If you have reg free COM all that's needed is that the COM library be copied into your build output folder.
我最终使用 BeforeBuild 目标显式调用 tlbimp.exe:
这确实需要引用 interop.comlibrary.dll 二进制文件,从而在第一次构建之前打开项目时,在 Visual Studio 中的引用上会出现一个小黄色警告标志。
I ended up using the BeforeBuild target to explicitly invoke tlbimp.exe:
This does require referencing the interop.comlibrary.dll binary, resulting in a little yellow warning sign on the reference in visual studio when opening the project before the first build.