How to validate a dynamic365 solution file before import using powershell or shell script

45 Views Asked by At

How to validate a dynamic365 solution file before import using powershell or shell script. The requirement is to validate it before import through a azure devops pipeline.

I have tried multiple Azure devops tasks but couldn't get success. The power app solution file only gives errors during import but we need it before import. Also tried installing powerApps CLI but it's not giving the desired reults.

1

There are 1 best solutions below

0
On BEST ANSWER

You should be able to do it using a powershell script.

param(
    [Parameter(Mandatory=$true)]
    [string]$SolutionFilePath
)

# Define the Common Data Service (CDS) environment URL
$environmentUrl = "https://<your-environment-name>.crm.dynamics.com"

# Import the required PowerShell modules
Import-Module Microsoft.PowerApps.Administration.PowerShell -DisableNameChecking
Import-Module Microsoft.Xrm.Data.Powershell -DisableNameChecking

try {
    # Connect to the Common Data Service environment
    Connect-PowerAppsEnvironment -EnvironmentUrl $environmentUrl

    # Validate the PowerApp solution file
    $validationResult = Test-AppSolution -Path $SolutionFilePath

    # Check the validation result
    if ($validationResult.IsValid) {
        Write-Host "PowerApp solution file is valid."
    }
    else {
        Write-Host "PowerApp solution file is not valid."
        Write-Host "Validation errors:"
        $validationResult.ValidationFailures | ForEach-Object {
            Write-Host "- $($_.Message)"
        }
    }
}
catch {
    Write-Host "An error occurred while validating the PowerApp solution file:"
    Write-Host $_.Exception.Message
}
finally {
    # Disconnect from the Common Data Service environment
    Disconnect-PowerAppsEnvironment
}