什么是.NET4新不软功能的优点[部署PIA的] [英] what is the advantage of .net4's new no pia feature [deploying PIA's]

查看:175
本文介绍了什么是.NET4新不软功能的优点[部署PIA的]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它可能我只是失去了一些东西,但是,当我写了一些code为Excel互操作,在这里是怎么一回事。

Its possibly im just missing something here but, when I write some code for Excel interop, here is how it goes.

  • 在我的引用添加到Excel的COM库。
  • VS创建一个PIA - (?通过TLBIMP右)的Microsoft.Office.Interop.Excel ....
  • 我的EXE和互操作(PIA)DLL复制到任何一台机器(使用.NET)和它的作品?

有这样一个场景,我将不得不部署/注册PIA?还是有我有什么错在这里,是因为在我看来,嵌入PIA到主体似乎并不像一个大大的功能?

Is there a scenario where I would have to deploy/register the PIA? Or have I got something wrong here, because it seems to me embedding the PIA into the main assembly doesn't seem like a great big feature?

请原谅我的无知,如果有的话。

Please excuse my ignorance, if any.

更新:
所以,我做了一些测试,我写打开Excel中添加了你好单元格中,并保存文件的应用程序。

Update:
So I did some tests, I wrote an app that opens excel adds "hello" in a cell and saves the file.

我建立它在我的Win7开发机安装的Office 2003(所以我引用的2003库)。有趣的是,没有嵌入PIA的应用程序是 9KB (3 PIA总量高达1.32MB)。随着嵌入式PIA的exe文件是 13KB

I built it on my Win7 Dev machine with Office 2003 installed(So I referenced 2003 libs). Interestingly, without embedded PIA's the app is 9KB (The 3 PIA's total upto 1.32MB). With embedded PIA's the exe is 13KB.

其次,嵌入式PIA,应用程序工作的计算机上使用Office的 2007年和2010年。嵌入式PIA,在WinXP + Office2007的只有失败的时候PIA的没有在exe文件的目录。

Secondly, with embedded PIA, the app worked on a machine with Office 2007 and 2010. And without embedded PIA, on WinXP+Office2007 it failed only when the PIA's were not in the exe's directory.

所以我猜什么方法,有某种动态的分辨率是多少?然后,为什么它在一个Win7没有PIA的EXE文件目录中的工作,但在WinXP失败(只有当PIA的没有在exe文件的目录),做了Win7的盒子有PIA的prolly全局什么部署?

So I guess whatever method, there is some kind of dynamic resolution? And then why did it work on a Win7 without the PIA's in the exe directory, but on WinXP it failed (only when the PIA's were not in the exe's dir), did the Win7 box have the PIA's prolly deployed globally or something?

感谢
吉迪恩

推荐答案

这不是常见的实际需要PIA。你必须有一个,如果你暴露在Excel类型库的互操作类型的公开课之一。这又错了,当其他code使用你的类,并没有使用相同的互操作库。当他们从同一个组件来了一个类型在.NET中是唯一的相同。你会得到一个很难跨preT错误信息,如无法施展应用程序。在PIA确保每个人都在使用相同类型的。只要每个人都在使用相同的PIA版本,这本身就是一大难题。伴随着您的应用程序部署自己的互操作DLL是好的,如果你能避免这种情况。这就不难在大多数情况下。

It's not that common to actually need a PIA. You have to have one if you expose any interop types from the Excel type library in one of your public classes. This goes wrong when other code uses your class and doesn't use the same interop library. A type in .NET is only identical when they came from the same assembly. You'd get a difficult to interpret error message like "Cannot cast Application to Application". The PIA ensures that everybody is using the same type. As long as everybody is using the same PIA version, which in itself is a difficult problem. Deploying your own interop DLL along with your app is fine if you can avoid this. Which is not difficult in most scenarios.

这个问题解决了在.NET 4.0中通过一个称为等价类功能。它是特定于COM接口类型中,CLR认为它们相容时,它们具有相同的[的Guid]和相同的声明,不管什么部件包含其中。这是再所利用的嵌入互操作类型功能(同无PIA),编译器嵌入互操作类型的程序集的元数据。只有那些你真正使用。

This problem was solved in .NET 4.0 through a feature called 'type equivalence'. It is specific to COM interface types, the CLR considers them compatible when they have the same [Guid] and the same declaration, regardless what assembly contains them. This was then taken advantage of with the 'embed interop types' feature (same as 'no pia'), the compiler embeds the interop types in the metadata of your assembly. Only the ones you actually use.

所以,你不必再出货的互操作库,不需要的PIA。它是小了很多,因为你只需支付你实际使用的类型。这是划算的很多的,强烈推荐。

So you don't have to ship the interop library anymore and don't need the PIA. And it is a lot smaller since you only pay for the types you actually use. That's a lot of bang for the buck, strongly recommended.

这篇关于什么是.NET4新不软功能的优点[部署PIA的]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆