18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

.NET APPLICATION PROGRAMMING INTERFACE<br />

Assembly versioning and redirection<br />

When new <strong>ArcGIS</strong> libraries are installed onto a machine, the corresponding<br />

primary interop assemblies (PIA) are updated as well to ensure that the available<br />

PIAs always correspond to the current libraries.<br />

.NET applications that are built using a specific version of a strongly named<br />

assembly will attempt to bind to the same version of that assembly at runtime<br />

because a strong name includes the version number of the assembly.<br />

To allow applications that bind to <strong>ArcGIS</strong> assemblies to find the new PIAs<br />

without the need for developers to recompile against these new versions, <strong>ArcGIS</strong><br />

installs publisher policy files for each PIA. A publisher policy file is an assembly<br />

that redirects the assembly binding process to use a new assembly version. These<br />

policy files are installed to the general assembly cache (GAC) alongside the ESRI<br />

PIAs.<br />

For example, you will find the policy file policy.9.0.ESRI.<strong>ArcGIS</strong>.System.dll,<br />

which redirects all assembly binding calls for the ESRI.<strong>ArcGIS</strong>.System.dll PIA<br />

from all 9.0 and service pack assembly versions to the new current assembly<br />

version.<br />

Deploying an application using XCOPY will not<br />

copy the settings in the machine configuration<br />

file.<br />

ARCGIS DEVELOPMENT USING .NET<br />

Using .NET you can customize the <strong>ArcGIS</strong> applications, create standalone applications<br />

that use ESRI’s types, and extend ESRI’s types. For example, you can<br />

create a custom tool for ArcMap, a standalone application that uses the<br />

MapControl, or a custom layer. This section discusses several key issues related to<br />

developing with <strong>ArcGIS</strong> and .NET.<br />

Registering .NET components with COM<br />

Extending <strong>ArcGIS</strong> applications with custom .NET components requires registering<br />

the components in the COM registry and exporting the .NET assemblies to a<br />

type library (TLB). When developing a component, there are two ways to perform<br />

this task: you can use the RegAsm utility that ships with the .NET Framework<br />

SDK or Visual Studio .NET, which has a Register for COM Interop compiler<br />

flag.<br />

The example below shows an EditTools assembly being registered with COM.<br />

The /tlb parameter specifies that a type library should also be generated and the<br />

/codebase option indicates that the path to the assembly should be included in<br />

the registry settings. Both of these parameters are required when extending the<br />

<strong>ArcGIS</strong> applications with .NET components.<br />

regasm EditTools.dll /tlb:EditTools.tlb /codebase<br />

Visual Studio .NET performs this same operation automatically if you set the<br />

Register for COM Interop compiler flag; this is the simplest way to perform the<br />

registration on a development machine. To check a project’s settings, click Project<br />

Properties from the Project menu, then look at the Build property under Configuration<br />

Properties. The last item, Register for COM Interop, should be set to True.<br />

166 • <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong> <strong>Guide</strong><br />

Registering .NET classes in COM component categories<br />

Much of the extensibility of <strong>ArcGIS</strong> relies on COM component categories. In<br />

fact, most custom <strong>ArcGIS</strong> components must be registered in component categories<br />

appropriate to their intended context and function for the host application to

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!