Sitemap

Tuesday, January 16, 2018

Using alias for link entity attributes in MS CRM

We can read link entity attributes by aliasing link entity or attributes. Here we will be discussing second point.

It is as simple as keeping alias attribute for each field with alias name. Here important note is , if you give alias name is same as filed or attribute name as shown below fetchXML, you don't need to type cast with "AliasedValue" to read this field. You can read the value direclty how you read parent attributes.




<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
    <entity name='new_workorder'>
       <attribute name='new_name' />
       <order attribute='new_name' descending='false' />
       <link-entity name='incident' from='incidentid' to='new_workorderid' visible='false' link-type='outer' alias='a'>
           <attribute name='new_incidentnumber' alias='new_incidentnumber' />
       </link-entity>
     </entity>
 </fetch>

Here you can read "new_incidentnumber" field with any type casting to AliasedValue.



string incidentNumber = Convert.ToString(entityCollection.Entities[0].Attributes["new_incidentnumber"]);
If you give alias name as different than field name then we should type cast with AliasedValue to read its value.










Thursday, January 4, 2018

Merge assemblies using ILMerge

Sometimes we do have requirement of using external dll in a plugin. So, to register our plugin we should merge it to make a single dll. Here we will be using ILMerge for merging the dlls. ILMerge is an utility which merges multiple .NET assemblies into a single assembly.

Download ILMerge utility here

Syntax:
Ilmerge.exe [/lib:directory]* [/log[:filename]] [/keyfile:filename [/delaysign]] [/internalize[:filename]] [/target]:(library|exe|winexe)] [/closed] [/debug] [/ver:version] [/copyattrs [/allowMultiple]] [/xmldocs] [/attr:filename] ([/targetplatform:<version>[,<platformdir>]]|v1|v1.1|v2|v4) [/useFullPublicKeyForReferences] [/zeroPeKind] [/wildcards] [/allowDup[:typename]]* [/allowDuplicateResources] [/union] [/align:n] /out:filename <primary assembly> [<other assemblies>...]

Out of all the options we basically use four major options to merge , below is the sample example for ILMerge.

ILMerge.exe /out:"C:\ILMerge\Primary.dll" /lib:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319" /targetplatform:"v4,C:\Windows\Microsoft.NET\Framework64\v4.0.30319" /keyfile:"Your path to .snk file" "C:\Main\Primary.dll" "C:\Main\Secondary.dll"

/out:  This must be set before calling Merge. It specifies the path and filename that the target assembly will be written to.

/lib: If specified, this sets the directories to be used to search for input assemblies. We do set the path for .Net Framework 4.0.

/targetplatform: This method sets the .NET Framework for the target assembly to be the one specified by platform. Valid strings for the first argument are "v1", "v1.1", "v2", and "v4". The "v" is case insensitive and is also optional. This way ILMerge can be used to "cross-compile", i.e., it can run in one version of the framework and generate the target assembly so it will run under a different assembly. The second argument is the directory in which mscorlib.dll is to be found

/keyfile: When this is set before calling Merge, it specifies the path and filename to a .snk file. The target assembly will be signed with its contents and will then have a strong name