Closed jozefizso closed 1 year ago
Adding the NetOfficeFw.Excel v1.9.1 package to a new .NET Framework console application project which used the packages.config
file to manage NuGet packages will produce project which cannot be compiled:
// error CS1752: Interop type 'Core' cannot be embedded. Use the applicable interface instead.
NetOffice.Core.Default.Console.WriteLine("NetOffice bug #371");
// error CS1752: Interop type 'Application' cannot be embedded. Use the applicable interface instead.
var app = new NetOffice.ExcelApi.Application();
NuGet will add <EmbedInteropTypes>True</EmbedInteropTypes>
setting by default:
<Reference Include="ExcelApi, Version=1.9.1.0, Culture=neutral, PublicKeyToken=297f57b43ae7c1de, processorArchitecture=MSIL">
<HintPath>packages\NetOfficeFw.Excel.1.9.1\lib\net462\ExcelApi.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="NetOffice, Version=1.9.1.0, Culture=neutral, PublicKeyToken=297f57b43ae7c1de, processorArchitecture=MSIL">
<HintPath>packages\NetOfficeFw.Core.1.9.1\lib\net462\NetOffice.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
Developer must manually change the v1.9.1 package references to no embed interop types.
See https://gist.github.com/jozefizso/b0ce227e2824a2ac9ecccd2ecd167567
NetOffice packages used the PowerShell script to configure the project file with correct
EmbedInteropTypes
setting. As we moved to thedotnet pack
format of packages, these PowerShell scripts are no longer used.We must update packages so NetOffice libraries are referenced using the
<EmbedInteropTypes>False</EmbedInteropTypes>
setting.See https://github.com/NuGet/Samples/tree/main/NuGet.Samples.Interop See https://stackoverflow.com/questions/46353244/embed-interop-types-to-false-in-nuget-package See https://github.com/NuGet/Home/wiki/Embed-Interop-Types-with-PackageReference