简体   繁体   English

在C#/ .NET 4.0中新的NoPIA和Type Equivalence功能是否意味着不再需要Microsoft.mshtml.dll

[英]Do the new NoPIA and Type Equivalence features in C#/.NET 4.0 mean Microsoft.mshtml.dll is no longer needed

I'm maintaining a WPF based application which contains a WinForms based WebBrowser control that based on the IE web browser control. 我正在维护一个基于WPF的应用程序,它包含一个基于WinForms的WebBrowser控件,该控件基于IE Web浏览器控件。 When we deploy, we have had to also supply Microsoft.mshtml.dll and do some custom configuration stuff for our ClickOnce publishing process as well in order to get things to work. 当我们部署时,我们还必须提供Microsoft.mshtml.dll并为ClickOnce发布过程执行一些自定义配置,以便让事情发挥作用。

I'm curious that with the new NoPIA and Type Equivalence features and dynamic type capabilities in C# 4.0 can we expect that if we upgrade that we can remove the dependencies on the Microsoft.mshtml.dll assembly? 我很好奇,使用C#4.0中新的NoPIAType Equivalence功能以及动态类型功能,我们可以期望如果我们升级它,我们可以删除对Microsoft.mshtml.dll程序集的依赖吗? If so this will not only reduce the size of our deployment quite a bit but will also simplify our publishing process as well. 如果是这样,这不仅会减少我们部署的规模,而且还会简化我们的发布过程。

It is my understanding that we should be able embed the types that normally get automatically generated into extra assemblies for COM types such as the MapPoint Control by Visual Studio. 我的理解是,我们应该能够将通常自动生成的类型嵌入到COM类型的额外程序集中,例如Visual Studio的MapPoint控件。 I don't know if this also applies to the Microsoft.mshtml.dll or even how it is done even in the most simple of cases. 我不知道这是否也适用于Microsoft.mshtml.dll甚至是在最简单的情况下它是如何完成的。 If somebody could provide an explanation about what the practical impact of these new features are on a project that relies on COM interop and especially the Microsoft.mshtml.dll assembly it would be of great help to me. 如果有人可以解释这些新功能对依赖COM互操作的项目的实际影响,特别是Microsoft.mshtml.dll程序集,那将对我有很大帮助。

Absolutely, that's what it is all about. 当然,这就是它的全部意义。 Import your solution into VS2010, Project + Properties, Application tab, change the Target Framework to .NET 4.0. 将您的解决方案导入VS2010,Project + Properties,Application选项卡,将Target Framework更改为.NET 4.0。 Open the References node in the Solution Explorer window, select the Microsoft.mshtml reference and set its "Embed Interop Type" property to True. 在Solution Explorer窗口中打开References节点,选择Microsoft.mshtml引用并将其“Embed Interop Type”属性设置为True。 It is automatically turned on for new projects that target 4.0 对于以4.0为目标的新项目,它会自动打开

This works for any COM type library that you selected on the COM tab as well as any PIA you selected in the .NET tab. 这适用于您在COM选项卡上选择的任何COM类型库以及您在.NET选项卡中选择的任何PIA。 The type library is only required at build time, you don't have to deploy the interop libraries or PIAs anymore. 类型库仅在构建时需要,您不必再部署互操作库或PIA。 The actual COM server must of course still be present on the target machine. 当然,实际的COM服务器必须仍然存在于目标机器上。

The new dynamic keyword and the optional and named argument features are not related, they merely make it easier to write cleaner code when working with COM servers that were designed to work with scripting languages. 新的动态关键字以及可选和命名的参数功能不相关,它们只是在使用旨在使用脚本语言的COM服务器时更容易编写更干净的代码。 Mshtml is already pretty clean, Office interop is the best example. Mshtml已经相当干净,Office interop就是最好的例子。

Also note that it tends to be easy to avoid taking a dependency on mshtml when you leverage the Windows Forms' HtmlDocument and HtmlElement classes. 另请注意,在利用Windows窗体的HtmlDocument和HtmlElement类时,很容易避免依赖于mshtml。 That gets started by using the WebBrowser.Document property. 这是通过使用WebBrowser.Document属性开始的。 They however don't wrap all mshtml features. 但是它们不包含所有mshtml功能。

C# 4.0 can we expect that if we upgrade that we can remove the dependencies on the Microsoft.mshtml.dll assembly? C#4.0我们可以期望,如果我们升级,我们可以删除Microsoft.mshtml.dll程序集的依赖项吗?

You will still need the dependency to build your assembly, but it is not needed at runtime (and VS will not copy it to the output directory) 您仍然需要依赖项来构建程序集,但在运行时不需要它(并且VS不会将其复制到输出目录)

Providing you have set the "Embed Interop Types" setting in the properties of the reference to MSHTML set to "True". 如果已将MSHTML引用属性中的“嵌入互操作类型”设置设置为“True”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM