使 .NET Standard 库 COM 可见?
Make a .NET Standard library COM-Visible?
对于完整的 .NET 项目,您可以勾选一个框以使项目 COM 在 Project Properties > Application tab > Assembly Information..
中可见:
但是,.NET Standard 项目不存在 Assembly Information..
按钮,而是在 Project Properties > Package tab
上输入数据,但该选项卡没有 [=13] 的复选框=]:
您仍然可以通过其他方法使 .NET Standard 库 COM 可见,还是出于某种原因这样做没有意义?
@ZdeněkJelínek 在对该问题的评论中提出了一个有趣的观点,即 .NET Standard 应该与平台无关,而 COM 本质上是特定于平台的。
为了检验该理论,我将 the example of COM interop in the C# documentation 中的代码放入完整的 .NET 解决方案和 .NET Standard 解决方案中。这是代码:
using System.Runtime.InteropServices;
namespace project_name
{
[Guid("EAA4976A-45C3-4BC5-BC0B-E474F4C3C83F")]
public interface ComClass1Interface
{
}
[Guid("7BD20046-DF8C-44A6-8F6B-687FAA26FA71"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ComClass1Events
{
}
[Guid("0D53A3E8-E51A-49C7-944E-E72A2064F938"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(ComClass1Events))]
public class ComClass1 : ComClass1Interface
{
}
}
在完整的 .NET 中编译良好,在 .NET 标准中它编译良好,但触发此警告:
'ComInterfaceType.InterfaceIsIDispatch' is obsolete: 'Support for
IDispatch may be unavailable in future releases.'
所以一开始这似乎证实了这一点,目前您可以添加 COM 接口,但根据设计它们不应再存在。 However, that warning shows up in the dotnet standard github repo,关于这些成员是否真的过时,似乎还没有明确的结论。
此外,System.Runtime.InteropServices.ComVisibleAttribute
出现在 this check in for a .NET Stansard 1.6 check in for the System.Runtime.Forwards.cs
class in the netstandard codebase, but I don't understand the codebase well enough to know why it's there. Accordingly, I've asked the question on the .NET Standard repo 并在此处报告答案。
我在 GitHub 评论了你的问题。如果您选择的运行时同时支持 .NET Standard 和 COM 可见性,您绝对可以使 .NET Standard 库 COM 可见。
这是一个使用 Visual Studio 2017 和 WiX 的示例:
ComVisibleNetStandard
对于完整的 .NET 项目,您可以勾选一个框以使项目 COM 在 Project Properties > Application tab > Assembly Information..
中可见:
但是,.NET Standard 项目不存在 Assembly Information..
按钮,而是在 Project Properties > Package tab
上输入数据,但该选项卡没有 [=13] 的复选框=]:
您仍然可以通过其他方法使 .NET Standard 库 COM 可见,还是出于某种原因这样做没有意义?
@ZdeněkJelínek 在对该问题的评论中提出了一个有趣的观点,即 .NET Standard 应该与平台无关,而 COM 本质上是特定于平台的。
为了检验该理论,我将 the example of COM interop in the C# documentation 中的代码放入完整的 .NET 解决方案和 .NET Standard 解决方案中。这是代码:
using System.Runtime.InteropServices;
namespace project_name
{
[Guid("EAA4976A-45C3-4BC5-BC0B-E474F4C3C83F")]
public interface ComClass1Interface
{
}
[Guid("7BD20046-DF8C-44A6-8F6B-687FAA26FA71"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ComClass1Events
{
}
[Guid("0D53A3E8-E51A-49C7-944E-E72A2064F938"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(ComClass1Events))]
public class ComClass1 : ComClass1Interface
{
}
}
在完整的 .NET 中编译良好,在 .NET 标准中它编译良好,但触发此警告:
'ComInterfaceType.InterfaceIsIDispatch' is obsolete: 'Support for IDispatch may be unavailable in future releases.'
所以一开始这似乎证实了这一点,目前您可以添加 COM 接口,但根据设计它们不应再存在。 However, that warning shows up in the dotnet standard github repo,关于这些成员是否真的过时,似乎还没有明确的结论。
此外,System.Runtime.InteropServices.ComVisibleAttribute
出现在 this check in for a .NET Stansard 1.6 check in for the System.Runtime.Forwards.cs
class in the netstandard codebase, but I don't understand the codebase well enough to know why it's there. Accordingly, I've asked the question on the .NET Standard repo 并在此处报告答案。
我在 GitHub 评论了你的问题。如果您选择的运行时同时支持 .NET Standard 和 COM 可见性,您绝对可以使 .NET Standard 库 COM 可见。
这是一个使用 Visual Studio 2017 和 WiX 的示例: ComVisibleNetStandard