Skip to content

Commit

Permalink
Added Sample Solution and re-factored the VSTS Tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
WaelHamze committed Jan 15, 2017
1 parent 6c3049e commit 5dc0fbd
Show file tree
Hide file tree
Showing 126 changed files with 18,045 additions and 57 deletions.
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,13 @@
/CRM365/Xrm.Framework.CI/bin
/CRM365/Xrm.Framework.CI/Xrm.Framework.CI.PowerShell.Scripts/Xrm.Framework.CI.PowerShell.Scripts.pssproj.user
/CRM365/Xrm.Framework.CI/.vs/config/applicationhost.config
/CRM365/Xrm.Framework.CI.Sample/.vs/config
/CRM365/Xrm.Framework.CI.Sample/packages
/CRM365/Xrm.Framework.CI.Sample/Xrm.Framework.CI.Sample.CRMPackage/bin
/CRM365/Xrm.Framework.CI.Sample/Xrm.Framework.CI.Sample.CRMPackage/obj
*.user
/CRM365/Xrm.Framework.CI.Sample/Xrm.Framework.CI.Sample.Plugins/bin
/CRM365/Xrm.Framework.CI.Sample/Xrm.Framework.CI.Sample.WFActivities/bin
/CRM365/Xrm.Framework.CI.Sample/Xrm.Framework.CI.Sample.WFActivities/obj/Debug
/CRM365/Xrm.Framework.CI.Sample/Xrm.Framework.CI.Sample.WFActivities/obj/Release
/CRM365/Xrm.Framework.CI.Sample/Xrm.Framework.CI.Sample.Plugins/obj
8 changes: 8 additions & 0 deletions CRM365/Xrm.Framework.CI.Sample/ConfigSchema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<entity name="wh_config" displayname="Config" etc="10188" primaryidfield="wh_configid" primarynamefield="wh_key" disableplugins="false">
<fields>
<field updateCompare="true" displayname="Key" name="wh_key" type="string" customfield="true" />
<field displayname="Value" name="wh_value" type="string" customfield="true" />
</fields>
</entity>
</entities>
16 changes: 16 additions & 0 deletions CRM365/Xrm.Framework.CI.Sample/ExtractXrmCIFrameworkSample.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[CmdletBinding()]

param
(
[string]$connectionString #The connection string as per CRM Sdk
)

$ErrorActionPreference = "Stop"

#Script Location
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
Write-Verbose "Script Path: $scriptPath"

Write-Verbose "ConnectionString = $connectionString"

& "$scriptPath\Lib\xRMCIFramework\ExtractCustomizations.ps1" -Verbose -solutionPackager "$scriptPath\Lib\xRMCIFramework\SolutionPackager.exe" -solutionFilesFolder "$scriptPath\SolutionFiles" -mappingFile "$scriptPath\XrmCIFrameworkSampleMapping.xml" -solutionName "XrmCIFrameworkSample" -connectionString $connectionString -TreatPackWarningsAsErrors $true
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#
# DeployPackage.ps1
#

param(
[string]$DeploymentType,
[string]$Username,
[string]$Password,
[string]$ServerUrl,
[string]$OrganizationName,
[string]$DeploymentRegion,
[string]$OnlineType,
[string]$PackageName,
[string]$PackageDirectory
)

$ErrorActionPreference = "Stop"

Write-Verbose 'Entering DeployPackage.ps1'

#Parameters
Write-Verbose "DeploymentType = $DeploymentType"
Write-Verbose "Username = $Username"
Write-Verbose "Password = ******"
Write-Verbose "ServerUrl = $ServerUrl"
Write-Verbose "OrganizationName = $OrganizationName"
Write-Verbose "DeploymentRegion = $DeploymentRegion"
Write-Verbose "OnlineType = $OnlineType"
Write-Verbose "PackageName = $PackageName"
Write-Verbose "PackageDirectory = $PackageDirectory"

#Script Location
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
Write-Verbose "Script Path: $scriptPath"

#Load XRM Tooling

Add-PSSnapin Microsoft.Xrm.Tooling.Connector

Add-PSSnapin Microsoft.Xrm.Tooling.PackageDeployment

#Create Credentials
$SecPassword = ConvertTo-SecureString $Password -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential ($Username, $SecPassword)

#Create Connection

switch($DeploymentType)
{
"Onpremises" { $CRMConn = Get-CrmConnection -ServerUrl $ServerUrl -OrganizationName $OrganizationName -Credential $Cred }
"Online" { $CRMConn = Get-CrmConnection -Credential $Cred -DeploymentRegion $DeploymentRegion –OnlineType $OnlineType –OrganizationName $OrganizationName }
}

#Deploy Package

Import-CrmPackage –CrmConnection $CRMConn –PackageDirectory $PackageDirectory –PackageName $PackageName -Verbose

Write-Verbose 'Leaving DeployPackage.ps1'
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#
# Filename: ExtractCustomizations.ps1
#
param([string]$solutionPackager, #The full path to the solutionpackager.exe
[string]$solutionFilesFolder, #The folder to extract the CRM solution
[string]$mappingFile, #The full path to the mapping file
[string]$solutionName, #The unique CRM solution name
[string]$connectionString, #The connection string as per CRM Sdk
[bool]$TreatPackWarningsAsErrors)

$ErrorActionPreference = "Stop"

Write-Verbose 'Entering ExtractCustomizations.ps1'

Write-Verbose "Solution Packager = $solutionPackager"
Write-Verbose "Solution Files Folder = $solutionFilesFolder"
Write-Verbose "Mapping File = $mappingFile"
Write-Verbose "ConnectionString = $connectionString"
Write-Verbose "TreatPackWarningsAsErrors = $TreatPackWarningsAsErrors"

# CI Toolkit
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
$xrmCIToolkit = $scriptPath + "\Xrm.Framework.CI.PowerShell.Cmdlets.dll"
Write-Verbose "Importing CIToolkit: $xrmCIToolkit"
Import-Module $xrmCIToolkit

#Export Solutions
Write-Output "Exporting Solutions to: " $env:TEMP
$unmanagedSolution = Export-XrmSolution -ConnectionString $connectionString -Managed $False -OutputFolder $env:TEMP -UniqueSolutionName $solutionName
Write-Output "Exported Solution: $unmanagedSolution"
$managedSolution = Export-XrmSolution -ConnectionString $connectionString -Managed $True -OutputFolder $env:TEMP -UniqueSolutionName $solutionName
Write-Output "Exported Solution: $managedSolution"

#Solution Packager
$extractOuput = & "$solutionPackager" /action:Extract /zipfile:"$env:TEMP\$unmanagedSolution" /folder:"$solutionFilesFolder" /packagetype:Both /errorlevel:Info /allowWrite:Yes /allowDelete:Yes /map:$mappingFile
Write-Output $extractOuput
if ($lastexitcode -ne 0)
{
throw "Solution Extract operation failed with exit code: $lastexitcode"
}
else
{
if (($extractOuput -ne $null) -and ($extractOuput -like "*warnings encountered*"))
{
if ($TreatPackWarningsAsErrors)
{
throw "Solution Packager encountered warnings. Check the output."
}
else
{
Write-Warning "Solution Packager encountered warnings. Check the output."
}
}
else
{
Write-Host "Solution Pack Completed Successfully"
}
}

# End of script

Write-Verbose 'Leaving ExtractCustomizations.ps1'
115 changes: 115 additions & 0 deletions CRM365/Xrm.Framework.CI.Sample/Lib/xRMCIFramework/ImportSolution.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#
# Filename: ImportSolution.ps1
#
param(
[string]$solutionFile, #The absolute path to the solution file zip to be imported
[string]$crmConnectionString, #The target CRM organization connection string
[bool]$override, #If set to 1 will override the solution even if a solution with same version exists
[bool]$publishWorkflows, #Will publish workflows during import
[bool]$overwriteUnmanagedCustomizations, #Will overwrite unmanaged customizations
[bool]$skipProductUpdateDependencies, #Will skip product update dependencies
[bool]$convertToManaged, #Direct the system to convert any matching unmanaged customizations into your managed solution. Optional.
[bool]$holdingSolution,
[string]$logsDirectory, #Optional - will place the import log in here
[string]$logFilename #Optional - will use this as import log file name
)

$ErrorActionPreference = "Stop"

Write-Verbose 'Entering ImportSolution.ps1'

#Script Location
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
Write-Verbose "Script Path: $scriptPath"

#Load XrmCIFramework
$xrmCIToolkit = $scriptPath + "\Xrm.Framework.CI.PowerShell.Cmdlets.dll"
Write-Verbose "Importing CIToolkit: $xrmCIToolkit"
Import-Module $xrmCIToolkit
Write-Verbose "Imported CIToolkit"

Write-Verbose "solutionFile = $solutionFile"
Write-Verbose "crmConnectionString = $crmConnectionString"
Write-Verbose "override = $override"
Write-Verbose "publishWorkflows = $publishWorkflows"
Write-Verbose "overwriteUnmanagedCustomizations = $overwriteUnmanagedCustomizations"
Write-Verbose "skipProductUpdateDependencies = $skipProductUpdateDependencies"
Write-Verbose "convertToManaged = $convertToManaged"
Write-Verbose "holdingSolution = $holdingSolution"
Write-Verbose "logsDirectory = $logsDirectory"
Write-Verbose "logFilename = $logFilename"

Write-Verbose "Getting solution info from zip"

$solutionInfo = Get-XrmSolutionInfoFromZip -SolutionFilePath $solutionFile

Write-Host "Solution Name: " $solutionInfo.UniqueName
Write-Host "Solution Version: " $solutionInfo.Version

$solution = Get-XrmSolution -ConnectionString $CrmConnectionString -UniqueSolutionName $solutionInfo.UniqueName

if ($solution -eq $null)
{
Write-Host "Solution not currently installed"
}
else
{
Write-Host "Solution Installed Current version: " $solution.Version
}

if ($override -or ($solution -eq $null) -or ($solution.Version -ne $solutionInfo.Version))
{
Write-Verbose "Importing Solution: $solutionFile"

$importJobId = [guid]::NewGuid()

$asyncOperationId = Import-XrmSolution -ConnectionString $CrmConnectionString -SolutionFilePath $solutionFile -publishWorkflows $publishWorkflows -overwriteUnmanagedCustomizations $overwriteUnmanagedCustomizations -SkipProductUpdateDependencies $skipProductUpdateDependencies -ConvertToManaged $convertToManaged -HoldingSolution $holdingSolution -ImportAsync $true -WaitForCompletion $true -ImportJobId $importJobId -Verbose

Write-Host "Solution Import Completed. Import Job Id: $importJobId"

if ($logsDirectory)
{
if ($logFilename)
{
$importLogFile = $logsDirectory + "\" + $logFilename
}
else
{
$importLogFile = $logsDirectory + "\" + $solutionInfo.UniqueName + '_' + ($solutionInfo.Version).replace('.','_') + '_' + [System.DateTime]::Now.ToString("yyyy_MM_dd__HH_mm") + ".xml"
}
}

$importJob = Get-XrmSolutionImportLog -ImportJobId $importJobId -ConnectionString $CrmConnectionString -OutputFile $importLogFile

$importProgress = $importJob.Progress
$importResult = (Select-Xml -Content $importJob.Data -XPath "//solutionManifest/result/@result").Node.Value
$importErrorText = (Select-Xml -Content $importJob.Data -XPath "//solutionManifest/result/@errortext").Node.Value


Write-Verbose "Import Progress: $importProgress"
Write-Verbose "Import Result: $importResult"
Write-Verbose "Import Error Text: $importErrorText"
Write-Verbose $importJob.Data

if (($importResult -ne "success") -or ($importProgress -ne 100))
{
throw "Import Failed"
}

$solution = Get-XrmSolution -ConnectionString $CrmConnectionString -UniqueSolutionName $solutionInfo.UniqueName

if ($solution.Version -ne $solutionInfo.Version)
{
throw "Import Failed"
}
else
{
Write-Host "Solution Imported Successfully"
}
}
else
{
Write-Host "Skipped Import of Solution..."
}

Write-Verbose 'Leaving ImportSolution.ps1'
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 5dc0fbd

Please sign in to comment.