编程语言
首页 > 编程语言> > c#-为VBA公开.NET(COM)tlb库时选择自定义引用名称添加引用对话框

c#-为VBA公开.NET(COM)tlb库时选择自定义引用名称添加引用对话框

作者:互联网

我所拥有的是一个Excel 2010 VBA客户端正在使用的C#.NET 4.5 ComVisible(true)库.

我有两个问题:

1-

在VBA中,当我从“工具->引用”添加对tlb的引用时,出现“可用引用”对话框,该对话框将库引用名称显示为与.tlb文件相同的名称,但没有扩展名.如果我的.tlb文件有空格,那么它将在对话框中替换为下划线.

以下线程讨论了类似的问题,但是从VBA项目的角度来看:
How can I put spaces in my VBA project name?

From my C# project, how can I control the name that will appear in “Available References”
(including using spaces)?

2-

关于我的库的名称空间,如何选择一个独立于我的引用名称和.tlb名称的名称空间?例如:

Dim oMyTest As New MyCustomNameSpace.MyTest

我已经在C#中尝试了以下方法,但是它没有用,它总是选择.tlb文件名作为名称空间:

[ProgId("MyCustomNameSpace.MyTest")]
public class MyTest: IMyTest

What do I need to change in C# to control my namespace within VBA?

解决方法:

MSDN Library section中详细描述了从程序集到类型库的转换.“导出的程序集转换”文章提供了您要询问的相关详细信息.引用它们:

Assembly names often contain periods, which are not permitted in type library names. The export process converts periods in the name field of an assembly to underscores.

The export process copies the AssemblyDescriptionAttribute if applied to an assembly at design time, to the helpstring or DocString associated with a type library. Neither the HelpFile field nor the HelpContext field in the type library is set. None of the LIBFLAGS in the type library is set.

请注意,默认情况下,ASsemblyInfo.cs中的[assembly:AssemblyDescription]属性使用空字符串.您可以直接对其进行编辑,也可以使用“项目属性”,“应用程序”选项卡,“装配信息”按钮.

标签:interop,com-interop,c,vba,excel-vba
来源: https://codeday.me/bug/20191031/1978017.html