New NoPIA and Type Equivalence features in C # /. NET 4.0 mean Microsoft.mshtml.dll is no longer required

I support a WPF-based application that contains a WinForms-based WebBrowser control that is based on the IE web browser control. When we deploy, we must also supply Microsoft.mshtml.dll and make some custom configuration items for our ClickOnce publishing process, as well as for getting it to work.

I'm curious that with the new NoPIA and equivalence properties of type dynamic in C # 4.0, can we expect that if we update this, we can remove the dependencies on the Microsoft.mshtml.dll assembly? If so, this will not only reduce the size of our deployment just a little, but also simplify our publishing process.

I understand that we must be able to implement types that are usually automatically generated in additional assemblies for COM types, such as MapPoint Control, using Visual Studio. I do not know if this also applies to Microsoft.mshtml.dll or even how it is done even in the simplest cases. If someone can give an explanation of the practical impact of these new features on a project that relies on COM interoperability, and especially on the Microsoft.mshtml.dll assembly, that would help me a lot.

+4
source share
2 answers

Absolutely, that's what everything is about. Import your solution into VS2010, Project + Properties, Application tab, change Target Framework to .NET 4.0. Open the Links node in the Solution Explorer window, select the Microsoft.mshtml link and set the Paste Interaction Type property to True. It automatically turns on for new projects focused on 4.0

This works for any COM type library selected on the COM tab, as well as any PIA selected on the .NET tab. A type library is only required at build time; you no longer need to deploy interop or PIA libraries. The actual COM server should, of course, still be present on the target machine.

The new dynamic keyword and the optional named argument functions are not connected, they simply simplify writing cleaner code when working with COM servers that were designed to work with scripting languages. Mshtml is already pretty clean, Office interop is a good example.

Also note that it is easy to avoid mshtml dependencies when using the Windows Forms HtmlDocument and HtmlElement classes. This begins by using the WebBrowser.Document property. However, they do not wrap all mshtml functions.

+7
source

With # 4.0, can we expect that if we update this, we can remove the dependencies in the Microsoft.mshtml.dll assembly?

You still need a dependency to build the assembly, but it is not needed at runtime (and VS will not copy it to the output directory)

If you set the option "Insert interaction types" in the properties of the link to MSHTML set to "True".

+2
source

Source: https://habr.com/ru/post/1308866/


All Articles