0

Our Net6 application uses Excel Interop via COMReference in the csproj file.

    <COMReference Include="Microsoft.Office.Interop.Excel">
      <WrapperTool>tlbimp</WrapperTool>
      <VersionMinor>9</VersionMinor>
      <VersionMajor>1</VersionMajor>
      <Guid>00020813-0000-0000-c000-000000000046</Guid>
      <Lcid>0</Lcid>
      <Isolated>false</Isolated>
      <EmbedInteropTypes>true</EmbedInteropTypes>
      <CopyLocal>true</CopyLocal>
    </COMReference>

This works, embedding the required subset of interop types in the Net6 assembly.

However, if I set EmbedInteropTypes to false, msbuild copies a couple of Net Framework assemblies to the bin folder. These assemblies themselves reference stdole and Microsoft.Vbe.Interop from the GAC.

Are these Net4, Net2 (Vbe), and Net1 (stdole) assemblies safe for use in a Net6-windows application? Things seem to work locally, but I'm concerned that it may be a bit flakey and not work in other environments.

If a user has a (current) Windows OS and Office installed, will they also have these assemblies in the GAC? Or should I distribute stdole and the Vbe assembly with my application?

[The reason I want to consider disabling embedding is that our obfuscation tool mangles the embedded interop types if it merges two assemblies that have them.]

Another question: Why are embedded interop types not visible to other assemblies that reference the one containing the embedded types? Is there a way to make them available outside the containing assembly?

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Rob
  • 4,327
  • 6
  • 29
  • 55

1 Answers1

1

The files you are referring to are all interop files required for marshalling calls between unmanaged and managed environments. A primary interop assembly is a unique, vendor-supplied assembly that contains type definitions (as metadata) of types implemented with COM. See Primary Interop Assemblies for more information. Specifically, for the stdole.dll file you may find the What does stdole.dll do? thread.

If a user has a (current) Windows OS and Office installed, will they also have these assemblies in the GAC? Or should I distribute stdole and the Vbe assembly with my application?

By default, Windows and Office installations don't include interop files. That is solely your responsibility to include them with your software (where they are going to be used) if they are required. There is a small chance that anybody else wants to automate, for example, any Office application on the system, right? :)

However, the MS Office installer may install PIAs on the system (optional). That was one of the possible ways of retrieving PIAs on the computer.

The PIAs are automatically added to a location in the file system, outside of the global assembly cache, while you install Visual Studio. When you create a new project, Visual Studio automatically adds references to these copies of the PIAs to your project. Visual Studio uses these copies of the PIAs, instead of the assemblies in the global assembly cache, to resolve type references when you develop and build your project.

You can read more about possible ways of installation PIAs on the machine in the Office primary interop assemblies article.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45