如何在 Dot net core 项目中添加 COM 引用

问题描述

我正在使用 Visual Studio 2019 将 COM 引用添加到另一个项目。但我无法添加引用。出现以下错误

enter image description here

即使我已经创建了一个 COM.dll 文件并成功注册了 COM.comhost.dll 文件,但我无法解决的问题。

COM.csproj 文件

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <!--<OutputType>Exe</OutputType>-->
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <EnableComHosting>True</EnableComHosting>
    <EnableRegFreeCom Condition="'$(RegFree)' == 'True'">True</EnableRegFreeCom>
  </PropertyGroup>
  <Target Name="ServerUsage"
           Condition="'$(RegFree)' != 'True'"
           AfterTargets="Build">
    <Message Importance="High" Text="%0a************************************%0a*** $(MSBuildProjectName) usage instructions ***%0a************************************" />
    <Message Importance="High" Text="The server must be COM registered in order to activate.%0aThe following commands must be executed from an elevated command prompt." />
    <Message Importance="High" Text="Register:%0a    regsvr32.exe &quot;$(ProjectDir)$(OutputPath)$(ComHostFileName)&quot;" />
    <!--<Message Importance="High" Text="Unregister:%0a    regsvr32.exe /u &quot;$(ProjectDir)$(OutputPath)$(ComHostFileName)&quot;" />-->
  </Target>
</Project>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)