Outlook Interop in .NET Core 3.0?

孤人 提交于 2020-11-27 05:29:11

问题


I migrated our project from .NET Framework to .NET Core 3.0 (C#, WPF) and now I can not use Microsoft.Office.Interop.Outlook anymore, because it is not compatible with .NET Core 3.0. What I want to archive is opening/sending prefilled Outlook-Mails.

Is there an alternative to this interop dll, or maybe a way to use .NET Framework for only this reference?

Thanks and best regards!

Microsoft.Office.Interop.Outlook, NetOffice.Outlook


回答1:


This worked for me:

  1. Right click Dependencies and click "Add Reference"
  2. Select Microsoft Outlook 16.0 Object Library under the COM tab.
  3. Under Dependencies/COM in your project, select Interop.Microsoft.Office.Interop.Outlook reference, then under "Properties" set "Embed Interop Types" to "Yes"
  4. I also had to uninstall the Microsoft.Office.Interop.Outlook NuGet package because it caused a conflict with the reference in Dependencies/COM.

Outlook automation is now working fine.




回答2:


I am having the same issue when trying to use Microsoft.Office.Interop.Excel 15.0.4795.1000. It won't run when I target .net core 3.00 preview 7.

At this stage I do not think there is any other option than reverting back to .NEW Core 2.2.




回答3:


I had the same problem while migrating components with Office interop for Excel and Outlook to .NET Core 3.0. I found out that this is only a problem of the Nuget packages Microsoft.Office.Interop.Outlook and Microsoft.Office.Interop.Excel. The packages probably need an update to work with 3.0?

If I make direct references to the Interop assemblies all is working well. Here is a link to an example for this.

If you use Visual Studio, you need an additional workaround to achieve this. From the linked sample:

Adding COM references to .NET Core projects from Visual Studio is not currently supported. The workaround is to create a .NET Framework project, add the COM references, and then copy the relevant COMReference elements in the project.




回答4:


This is possible in a roundabout way. Here is how:

  1. Create a temporary .NET framework project.
  2. Add the references to COM components (Microsoft.Outlook.Interop).
  3. Open that csproj file and copy the entire those components are located in, over to your .NET Core project.

The nuget packages seem to be incompatible at the moment.

Reference: DotNet Samples



来源:https://stackoverflow.com/questions/56442139/outlook-interop-in-net-core-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!