Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed Interop Types settings for packages #371

Closed
jozefizso opened this issue Nov 16, 2022 · 1 comment · Fixed by #385
Closed

Embed Interop Types settings for packages #371

jozefizso opened this issue Nov 16, 2022 · 1 comment · Fixed by #385

Comments

@jozefizso
Copy link
Member

jozefizso commented Nov 16, 2022

NetOffice packages used the PowerShell script to configure the project file with correct EmbedInteropTypes setting. As we moved to the dotnet 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

@jozefizso
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment