FrameworkTemplate/Solutions/Scripts/SolutionExport.ps1

Param(
    [boolean] [Parameter(Mandatory = $false)] $DevMode = $false,
    [string] [Parameter(Mandatory = $true)] $StartPath
)

try {
    ######################## SETUP
    $ProgressPreference = 'SilentlyContinue'

    $message = @"
 
____ _ _ _ _____ _
/ ___| ___ | |_ _| |_(_) ___ _ __ | ____|_ ___ __ ___ _ __| |_
\___ \ / _ \| | | | | __| |/ _ \| '_ \ | _| \ \/ / '_ \ / _ \| '__| __|
 ___) | (_) | | |_| | |_| | (_) | | | | | |___ > <| |_) | (_) | | | |_
|____/ \___/|_|\__,_|\__|_|\___/|_| |_| |_____/_/\_\ .__/ \___/|_| \__|
                                                   |_|
 
v2
"@

    Write-Host $message
    Write-Host ""    

    Write-Host "Running for path : " $StartPath

    . (Join-Path $PSScriptRoot "_SetupTools.ps1")
    . (Join-Path $PSScriptRoot "_Config.ps1") -StartPath $StartPath

    $Text = $global:devops_SolutionName
    $UniqueId = "SolutionMGMT"

    $message = "Installing Solution Management Tools..."
    Write-Host $message


    Install-XrmModule
    Install-CoreTools
    Install-DevOpsDataModule

    ######################## GET CONNECTION
    if (!$Credentials) {
        $message = "Getting Credentials for $global:devops_ServerUrl"
        Write-Host $message

        $Credentials = Get-Credential -Message "Credentials : $global:devops_SolutionName @ $global:devops_ServerUrl"
    }
    if (!$UserName) {
        $UserName = $Credentials.GetNetworkCredential().UserName
        $Password = $Credentials.GetNetworkCredential().Password
    }

    $message = "Establishing connection to $global:devops_ServerUrl"
    Write-Host $message
    Write-Host $UserName
    Write-Host $Password
    [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
    [string]$CrmConnectionString = "AuthType=OAuth;Username=$UserName;Password=$Password;Url=$global:devops_ServerUrl;AppId=51f81489-12ee-4a9e-aaae-a2591f45987d;RedirectUri=app://58145B91-0C36-4500-8554-080854F2AC97;LoginPrompt=Auto"
    $conn = Get-CrmConnection -ConnectionString $CrmConnectionString -Verbose -MaxCrmConnectionTimeOutMinutes 5
    #$conn = Connect-CrmOnline -Credential $Credentials -ServerUrl $global:devops_ServerUrl
    Set-CrmConnectionTimeout -conn $conn -TimeoutInSeconds 300

    Write-Output($conn)

    ######################## Generate Config Migration data
    . (Join-Path $StartPath "_ConfigMigration.ps1")

    ######################## Generate Types
    If ($DevMode) {
        . (Join-Path $PSScriptRoot "_GenerateTypes.ps1") -StartPath $StartPath
    }

    ######################## UPDATE VERSION
    . (Join-Path $PSScriptRoot "_UpdateVersion.ps1")

    ######################## EXPORT Solution
    . (Join-Path $PSScriptRoot "_ExportSolution.ps1") -StartPath $StartPath -ErrorAction Stop

    ######################### CLEANING UP
    $message = "Cleaning Up..."
    Write-Host $message

    Remove-Item (Join-Path $StartPath "nuget.exe") -ErrorAction Ignore -Force
    Remove-Item (Join-Path $StartPath "Tools") -Force -Recurse -ErrorAction Ignore
    Remove-Item (Join-Path $StartPath "*.zip") -Force -ErrorAction Ignore

    $ProgressPreference = 'Continue'
    #Stop-Process -Id $PID
  
}
catch {
    pause
}
finally {
    
}