.NET core 3.0 and MS Office Interop
The solution to this is a bit quirky, but possible.
Create a new .NET Framework 4.X project. Add the relevant COM references to the project. Edit the .csproj
of your .NET Core 3.0 project and add the generated references from the .NET Framework project to the <ItemGroup>
tag.
It should look something similar to:
<ItemGroup>
<COMReference Include="Microsoft.Office.Core">
<Guid>{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}</Guid>
<VersionMajor>2</VersionMajor>
<VersionMinor>8</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>primary</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
... more references
</ItemGroup>
Do not use the NuGet packages, they are not compatible with .NET Core.
Update:
You can now add the COM references straight from the IDE (since Visual Studio 2019 v16.6):
I had the same issue. I fixed it by opening the reference properties and setting both "Copy Local" and "Embed Interop Types" to "Yes".
Update: This actually does the same thing as adding these 2 lines to the COM reference in the .csproj file.
<COMReference Include="Microsoft.Office.Core">
...
<EmbedInteropTypes>True</EmbedInteropTypes>
<Private>true</Private>
</COMReference>
The "Private" tag isn't mentioned in the accepted answers, but it prevents a lot of problems.