我正在尝试将一些代码从.net frame 4.7.1移植到.net core 3.0。
问题是我们有一个C++ COM 程序集,我们使用清单在 .net 项目中引用它。
我已将项目添加到新解决方案并添加了引用。创建了一个互操作 dll,但是当我尝试运行代码时,我收到异常
{"Could not load file or assembly 'Interop.MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.":"Interop.MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"}
该文件位于项目的输出文件夹中。实际的com程序集不是,但即使复制它也不起作用。
答案是,在Visual Studio中添加引用不适用于.net核心应用程序。
解决方案是创建一个 .net 框架应用,添加引用,然后将 csproj 的引用部分复制到 .net 核心项目中。
EmbedInteropTypes!!花了我很长时间才找到这个...!!
<Reference Include="Microsoft.Office.Interop.Excel, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">
<HintPath>Microsoft.Office.Interop.Excel.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>