DotNetMatt
DotNetMatt

Reputation: 688

Dynamics CRM Plugin and VSTS Build

Here is my scenario: we use Dynamics CRM Online 2015 Update 1. For this purpose, we have to develop some plugins. I use the latest version of the CRM SDK (v8.0.0). And we use Visual Studio Team Services + Visual Studio 2015 Enterprise Edition.

My plugins have some dependencies, for instance on Newtonsoft.Json.

I found out that to be able to deploy my plugins, I have to use ILMerge so that Newtonsoft.Json is merged to my plugin DLL and can be used by it once deployed. The method is described here: http://nicknow.net/dynamics-crm-ilmerge-dll-plugin/ And so far, it works fine!

The downside of this method is that the assemblies Microsoft.Crm.Sdk.Prox, Microsoft.Xrm.Sdk and Microsoft.IdentityModel must not be included in the merged assembly. To do that, I have to set their property "Copy local" to False.

That's fine for plugin deployment. But when I check-in my plugins, the build of VSTS fails because it is not able to find the 3 assemblies having Copy local set to False.

So my question is, in your opinion what would be the best way to handle this? Is it possible for example to add a script before the build that would set Copy local to True? How? Or if you could think of any other idea, please feel free :)

Upvotes: 1

Views: 960

Answers (3)

Eric de Maar
Eric de Maar

Reputation: 31

The VSTS build should not fail on the references. I have a build definition with a similar structure using ILMerge.Task which runs perfectly fine. The best thing to do is follow these steps:

  • Make sure you don't have any hard references in your project. Make sure you retrieve the Microsoft.CrmSdk.CoreAssemblies package via Nuget. This is probably the cause of your problems with your build server.
  • Get the ILMerge.Task package using Install-Package MSBuild.ILMerge.Task
  • Set the 'Copy local' attribute value for each reference (DLL) which has to be merged to 'true'. Make sure you set the 'Copy local' value of other references to false.
  • Make sure the referenced assemblies are merged in the correct order using the ILMergeOrder.txt file included in your project.

A file called 'ILMerge.props' will be added to your project. You should set two properties in this file:

<ILMergeAllowMultipleAssemblyLevelAttributes>true</ILMergeAllowMultipleAssemblyLevelAttributes>
<ILMergeCopyAttributes>true</ILMergeCopyAttributes>

These properties make sure that duplicate attributes over different assemblies are handled properly.

Upvotes: 1

Henk van Boeijen
Henk van Boeijen

Reputation: 7918

  • Do not use Microsoft v8 CRM-assemblies; these are part of Dynamics CRM 2016. For CRM 2015 you need v7.

  • Add NuGet-package Microsoft.CrmSdk.CoreAssemblies to your plugin project; it helps avoiding build problems.

  • Add NuGet-package ILMerge to the solution. It's installed at a default location.

  • Add a batch script to your project that is run as a post-build step. Your script should contain a merge step similar to this: "%SOLUTIONDIR%packages\ILMerge.2.14.1208\tools\ILMerge" /log:ILMerge.log /keyfile:"%KEYFILE%" /targetplatform:v4,"%PLATFORMDIR%" /out:tmp_merge\%PROJECTBINARY%.dll %PROJECTBINARY%.dll Newtonsoft.Json.dll

Upvotes: 2

MarioZG
MarioZG

Reputation: 2087

When using Ilmerge as command line, you can choose which dlls to include. In my projects I usually:

  • install NuGet package for IlMege
  • add post build event which calls ilmerge.exe and includes only libraries I need in final dll

Upvotes: 1

Related Questions