CRM Automate build Solution using Powershell commands

  • In CRM if there is any solution movement from other enviornment like DEV,PROD,STG we use to export the solution and import the solution to the respective environment by logging into MS Dynamics CRM.
  • This will tends to extra effort to do manually for developers or release managers.

  • So what if release user or test user can build and deploy the Solution deployment without CRM intervention(CRM loggin in)

  • We need to do some automate build and deployment.
  • In this article i write about how Import/Export solution automate to the various environment without intervention of logging into MS Dynamics CRM.
  • XRM CI Framework,this is one tool use to automate the build in CRM

      Below link is for download the XRM CI Framework



Download and extract the ZIP file .

First HelloWorld example “WhoAmIRequest”


1.Open "Powershell" and "Run as a Administrator"

2.Navigate to Extracted path and click PowerShell folder and set the Path to "C:\Users\subramanis\Desktop\CRM\CRM_SolutionAutomate\PowerShell"

3.Execute the below command
Import-Module ".\Xrm.Framework.CI.PowerShell.Dll"

Error:
Access Denied or Unable to load assembly error will occur
For Access denied ,make sure you have permisson to allow and Right click the Xrm.Framework.CI.PowerShell.Dll and unblock the dll
For Assembly unable load error,Execute the step no:3 in Powershell Version 2

4. Set the connection string of Online
Below is the format

//$con is variable,ServiceUri is the name of the connectionstring
$con="ServiceUri=https://2016crm123.crm.dynamics.com;Username=subramanicrm2016@2016crm123.onmicrosoft.com;Password=pass@123;"
//select-WhoAmI is the request pass to the service
//-ConnectionString is the set connectionstring to the request
//$response- result of the request data
//$response.UserId returns respective userid(GUID)
$response= select-WhoAmI -ConnectionString $con -Verbose
$response.UserId

After execute the query it will retun the GUID of the user which means we can able to access the data without logging into CRM

You could also invoke the Cmdlet with the –Verbose switch so it can give more information as it is executing.

Export the Solution using Power shell


  • You can use the Windows PowerShell ISE “powershell_ise.exe” to create your PowerShell Script. This provides Syntax highlighting and allows you to debug your PowerShell scripts.Let’s start. Declare any parameters you might need. These will make your script re-usable. For example in this case I am going to declare the connection string as a parameter, this will allow me to export my Sample solution from multiple environments.

  • Load the xRM CI Framework similar to what I have done in the first post. In this case the script is loading the PowerShell Module from the same directory to which I will be saving my script. Feel free to store the xRM CI Framework in a shared location and reference that location from your scripts.
  • Finally the important part. Use the “Export-XrmSolution” to export your Solution. In this case I am exporting the “Sample” solution to “C:\Temp” as managed. There are some optional parameters that you can still pass to this Cmdlet to specific other export options. Now your script should be ready see below.

  • Save the script to the same directory as the PowerShell assemblies and call it “ExportSampleSolution.ps1”


Let’s execute the script using PowerShell. You just need to pass the connection string as a parameter to this script.

Import Solution using powershell in CRM

Run the below command in the Powershell

Import-XrmSolution -ConnectionString "https://2016crm123.crm.dynamics.com;Username=subramanicrm2016@2016crm123.onmicrosoft.com;Password=pass@123;" -SolutionFilePath "C:\Temp\filename.zip" -PublishWorkflows $true -ConvertToManaged $false -OverwriteUnmanagedCustomizations $true ImportAsync $true -WaitForCompletion $true


Note:Manged solution should be imported as Manged solution






Comments

  1. This is helpful article. Thanks for sharing. I have one question.. I cant see the Solution name (i.e. Sample) in the Command..?

    ReplyDelete
  2. -SolutionFilepath here you need to mention the solutionname path means zip file

    ReplyDelete
  3. Thank you surely i will post blogs .Follow the below blog one of my friend
    http://alagunellaikumar.blogspot.com/?m=1

    ReplyDelete

Post a Comment

Popular posts from this blog

Asp.net- Encrypt and Decrypt connection strings in web.config file

Access the fields on Quick View Form – Dynamics CRM 2015