functions/invoke-d365compilerresultanalyzer.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141

<#
    .SYNOPSIS
        Analyze the compiler output log
         
    .DESCRIPTION
        Analyze the compiler output log and generate an excel file contain worksheets per type: Errors, Warnings, Tasks
         
        It could be a Visual Studio compiler log or it could be a Invoke-D365ModuleCompile log you want analyzed
         
    .PARAMETER Path
        Path to the compiler log file that you want to work against
         
        A BuildModelResult.log or a Dynamics.AX.*.xppc.log file will both work
         
    .PARAMETER OutputPath
        Path where you want the excel file (xlsx-file) saved to
         
    .PARAMETER SkipWarnings
        Instructs the cmdlet to skip warnings while analyzing the compiler output log file
         
    .PARAMETER SkipTasks
        Instructs the cmdlet to skip tasks while analyzing the compiler output log file
         
    .PARAMETER PackageDirectory
        Path to the directory containing the installed package / module
         
        Default path is the same as the AOS service "PackagesLocalDirectory" directory
         
        Default value is fetched from the current configuration on the machine
         
    .EXAMPLE
        PS C:\> Invoke-D365CompilerResultAnalyzer -Path "c:\temp\d365fo.tools\Custom\Dynamics.AX.Custom.xppc.log"
         
        This will analyse all compiler output log files generated from Visual Studio.
        It will use the default path for the OutputPath parameter.
         
        It will build error and error summary worksheets.
        It will build warning and warning summary worksheets.
        It will build task and task summary worksheets.
         
        A result set example:
         
        File Filename
        ---- --------
        c:\temp\d365fo.tools\Custom-CompilerResults.xlsx Custom-CompilerResults.xlsx
         
    .EXAMPLE
        PS C:\> Invoke-D365CompilerResultAnalyzer -Path "c:\temp\d365fo.tools\Custom\Dynamics.AX.Custom.xppc.log" -SkipWarnings
         
        This will analyse all compiler output log files generated from Visual Studio.
        It will use the default path for the OutputPath parameter.
         
        It will build error and error summary worksheets.
        It will build task and task summary worksheets.
         
        A result set example:
         
        File Filename
        ---- --------
        c:\temp\d365fo.tools\Custom-CompilerResults.xlsx Custom-CompilerResults.xlsx
         
    .EXAMPLE
        PS C:\> Invoke-D365CompilerResultAnalyzer -Path "c:\temp\d365fo.tools\Custom\Dynamics.AX.Custom.xppc.log" -SkipTasks
         
        This will analyse all compiler output log files generated from Visual Studio.
        It will use the default path for the OutputPath parameter.
         
        It will build error and error summary worksheets.
        It will build warning and warning summary worksheets.
         
        A result set example:
         
        File Filename
        ---- --------
        c:\temp\d365fo.tools\Custom-CompilerResults.xlsx Custom-CompilerResults.xlsx
         
    .NOTES
        Tags: Compiler, Build, Errors, Warnings, Tasks
         
        Author: Mötz Jensen (@Splaxi)
         
        This cmdlet is inspired by the work of "Vilmos Kintera" (twitter: @DAXRunBase)
         
        All credits goes to him for showing how to extract these information
         
        His blog can be found here:
        https://www.daxrunbase.com/blog/
         
        The specific blog post that we based this cmdlet on can be found here:
        https://www.daxrunbase.com/2020/03/31/interpreting-compiler-results-in-d365fo-using-powershell/
         
        The github repository containing the original scrips can be found here:
        https://github.com/DAXRunBase/PowerShell-and-Azure
#>

function Invoke-D365CompilerResultAnalyzer {
    [CmdletBinding()]
    [OutputType('')]
    param (
        [parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
        [Alias('LogFile')]
        [string] $Path,

        [string] $OutputPath = $Script:DefaultTempPath,

        [switch] $SkipWarnings,

        [switch] $SkipTasks,

        [string] $PackageDirectory = $Script:PackageDirectory
    )

    begin {
        Invoke-TimeSignal -Start

        if (-not (Test-PathExists -Path $PackageDirectory -Type Container)) { return }
    }

    process {

        $moduleName = ""

        if($Path -like "*Dynamics.AX.*.xppc.log"){
            $splittedString = $Path -split ".*Dynamics.AX.(.*).xppc.log"
            $moduleName = $splittedString[1]
        }elseif ($Path -like "*BuildModelResult.log"){
            $splittedString = $Path -split ".*\\(.*)\\BuildModelResult.log"
            $moduleName = $splittedString[1]
        }else{
            $moduleName = (New-Guid).Guid
        }

        $outputFilePath = Join-Path -Path $OutputPath -ChildPath "$moduleName-CompilerResults.xlsx"

        Invoke-CompilerResultAnalyzer -Path $Path -Identifier $moduleName -OutputPath $outputFilePath -SkipWarnings:$SkipWarnings -SkipTasks:$SkipTasks -PackageDirectory $PackageDirectory
    }
    
    end {
        Invoke-TimeSignal -End
    }
}