使.NET标准库COM-Visible?

问题描述 投票:3回答:2

对于完整的.NET项目,您可以勾选一个框以使项目COM在Project Properties > Application tab > Assembly Information..中可见:

enter image description here

但是,.NET标准项目不存在Assembly Information..按钮,而是在Project Properties > Package tab上输入数据,但该选项卡没有Make Assembly COM-Visible的复选框:

enter image description here

您是否仍然可以通过其他方法使.NET标准库COM可见,或者由于某种原因这样做是否有意义?

.net-standard
2个回答
2
投票

我在GitHub上评论了你的问题。如果您选择的运行时支持.NET标准和COM可见性,那么您绝对可以使.NET标准库COM可见。

以下是使用Visual Studio 2017和WiX的示例:ComVisibleNetStandard


0
投票

@ZdeněkJelínek在这个问题的评论中提出了一个有趣的观点,即.NET标准应该是平台无关的,而COM本身就是特定于平台的。

为了测试该理论,我将the example of COM interop in the C# documentation中的代码放在完整的.NET解决方案和.NET标准解决方案中。这是代码:

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'已过时:'未来版本中可能无法支持IDispatch。'

所以一开始似乎确认了它,目前你可以添加COM接口,但它们不应该在设计中存在。 However, that warning shows up in the dotnet standard github repo,似乎没有一个明确的结论,这些成员是否真的已经过时了。

此外,System.Runtime.InteropServices.ComVisibleAttribute出现在netstandard代码库中的this check in for a .NET Stansard 1.6 check in for the System.Runtime.Forwards.cs类中,但我不太了解代码库,因为它知道它为什么存在。因此,我有asked the question on the .NET Standard repo并在此报告答案。

© www.soinside.com 2019 - 2024. All rights reserved.