I am using the powershell script below to import a solution. It uses Microsoft.Xrm.Data.PowerShell, which in turn uses Microsoft.Xrm.Tooling.Connector.CrmServiceClient.ImportSolutionToCrm to import the solution. The code works just fine on my developer machine (Windows 7), but on our build agent (Windows Server 2012 R2), it hangs importing the CRM solution. With the XRM tooling tracing enabled and verbose turned on for the powershell commands, the last output I get is "Calling .ImportSolutionToCrm() this process can take minutes..." from the powershell module on the line before it calls the CrmServiceClient's ImportSolutionToCrm method. If I separately monitor the solution import logs in Dynamics 365, the solution imports fine in about 10-15 minutes. However, if I use Fiddler to watch the ImportSolutionRequest sent to the server, it just never completes. It stays at "download progress = 0 bytes."
I'm using the latest version of Microsoft.Xrm.Data.PowerShell (2.8.1.3), which in turn appears to use Microsoft.CrmSdk.XrmTooling.CoreAssembly version 9.0.2.4. I also have tried versions of Microsoft.Xrm.Data.PowerShell back to 2.8.0.
Also, this same script worked just fine on the same build agent before we upgraded Dynamics 365 from v8.2 to v9, and added the line about TLS 1.2 to the script. And, it works just fine if I use it to import a small test solution rather than our large solution.
I assume there's a setting somewhere in Windows on the build agent machines that causes the issue, but I'm not familiar with these things. Can anyone advise me where to look?
$username = 'my_username' $password = 'my_password' $orgname = 'my_org_name' $solutionFilePath = "$PSScriptRoot\my_solution.zip" Import-Module Microsoft.Xrm.Data.PowerShell # set up tracing $traceListener = New-Object System.Diagnostics.ConsoleTraceListener [Microsoft.Xrm.Tooling.Connector.TraceControlSettings]::TraceLevel = [System.Diagnostics.SourceLevels]::All [Microsoft.Xrm.Tooling.Connector.TraceControlSettings]::AddTraceListener($traceListener) # get the credential $securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force $credential = New-Object System.Management.Automation.PSCredential ($username, $securePassword) # connect to CRM [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 $conn = Get-CrmConnection -OrganizationName $orgname ` -OnLineType Office365 ` -Credential $credential ` -MaxCrmConnectionTimeOutMinutes 120 ` -ErrorAction Stop ` -Verbose # import the solution Import-CrmSolution -conn $conn -SolutionFilePath $solutionFilePath -MaxWaitTimeInSeconds 7200 -Verbose
It is hanging, not timing out. Interestingly, if I add a shorter timeout, say 20 minutes, then I get the timeout exception reported back once that time has passed, and the solution has actually imported successfully, so it's almost like things work then, except I don't want to have to depend exceptions.
We are trying Import-CrmSolutionAsync instead. That works on both my developer machine and the build agent machine. However, with it, we have what I assume is a separate issue, where in some Dynamics 365 instances, we get a SqlTimeout exception reported in the async job. The reason it seems separate is I can import the same solution to that instance using the synchronous import solution method from my developer machine, but if I try the async import from my developer machine to that instance, I get the SqlTimeout. So, I have a separate ticket open with Microsoft to look into the async issue, and am trying to see if I can figure out the synchronous issue in the meantime.
Is it hanging or is it timing out?
Have you tried using Import-CrmSolutionAsync instead?