英文:
Net6 COMReference and EmbedInteropTypes=false
问题
我们的Net6应用程序在csproj文件中通过COMReference使用Excel Interop。
这段代码工作正常,将所需的Interop类型子集嵌入到Net6程序集中。
然而,如果我将EmbedInteropTypes设置为false,msbuild会将一些Net Framework程序集复制到bin文件夹中。这些程序集本身引用了GAC中的stdole和Microsoft.Vbe.Interop。
这些Net4、Net2(Vbe)和Net1(stdole)程序集在Net6-Windows应用程序中是否安全可用?似乎在本地工作正常,但我担心在其他环境中可能不够稳定。
如果用户使用(当前的)Windows操作系统和Office安装,他们是否也会在GAC中拥有这些程序集?还是应该将stdole和Vbe程序集与我的应用程序一起分发?
[我考虑禁用嵌入的原因是我们的混淆工具会在合并了两个包含Interop类型的程序集时损坏嵌入的Interop类型。]
另一个问题:
为什么嵌入的Interop类型对其他引用包含嵌入类型的程序集不可见?有没有办法让它们在包含程序集之外可用?
英文:
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?
答案1
得分: 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.
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论