MegaBites-AI/Windows-powershell
0372
1# Copyright (c) Microsoft Corporation. All rights reserved.2# Licensed under the MIT License.3 4<#5.DESCRIPTION6Implement build and packaging of the package and place the output $OutDirectory/$ModuleName7#>8function DoBuild9{10 Write-Verbose -Verbose -Message "Starting DoBuild with configuration: $BuildConfiguration, framework: $BuildFramework"11 12 # Module build out path13 $BuildOutPath = "${OutDirectory}/${ModuleName}"14 Write-Verbose -Verbose -Message "Module output file path: '$BuildOutPath'"15 16 # Module build source path17 $BuildSrcPath = "bin/${BuildConfiguration}/${BuildFramework}/publish"18 Write-Verbose -Verbose -Message "Module build source path: '$BuildSrcPath'"19 20 # Copy psd1 file21 Write-Verbose -Verbose "Copy-Item ${SrcPath}/${ModuleName}.psd1 to ${OutDirectory}/${ModuleName}"22 Copy-Item "${SrcPath}/${ModuleName}.psd1" "${OutDirectory}/${ModuleName}"23 24 if ( Test-Path "${SrcPath}/code" ) {25 Write-Verbose -Verbose -Message "Building assembly and copying to '$BuildOutPath'"26 # build code and place it in the staging location27 Push-Location "${SrcPath}/code"28 try {29 # Get dotnet.exe command path.30 $dotnetCommand = Get-Command -Name 'dotnet' -ErrorAction Ignore31 32 # Check for dotnet for Windows (we only build on Windows platforms).33 if ($null -eq $dotnetCommand) {34 Write-Verbose -Verbose -Message "dotnet.exe cannot be found in current path. Looking in ProgramFiles path."35 $dotnetCommandPath = Join-Path -Path $env:ProgramFiles -ChildPath "dotnet\dotnet.exe"36 $dotnetCommand = Get-Command -Name $dotnetCommandPath -ErrorAction Ignore37 if ($null -eq $dotnetCommand) {38 throw "Dotnet.exe cannot be found: $dotnetCommandPath is unavailable for build."39 }40 }41 42 Write-Verbose -Verbose -Message "dotnet.exe command found in path: $($dotnetCommand.Path)"43 44 # Check dotnet version45 Write-Verbose -Verbose -Message "DotNet version: $(& ($dotnetCommand) --version)"46 47 # Build source48 Write-Verbose -Verbose -Message "Building with configuration: $BuildConfiguration, framework: $BuildFramework"49 Write-Verbose -Verbose -Message "Building location: PSScriptRoot: $PSScriptRoot, PWD: $pwd"50 & ($dotnetCommand) publish --configuration $BuildConfiguration --framework $BuildFramework --output $BuildSrcPath51 52 # Place build results53 if (! (Test-Path -Path "$BuildSrcPath/${ModuleName}.dll"))54 {55 throw "Expected binary was not created: $BuildSrcPath/${ModuleName}.dll"56 }57 58 Write-Verbose -Verbose -Message "Copying $BuildSrcPath/${ModuleName}.dll to $BuildOutPath"59 Copy-Item -Path "$BuildSrcPath/${ModuleName}.dll" -Dest "$BuildOutPath"60 61 if (Test-Path -Path "$BuildSrcPath/${ModuleName}.pdb")62 {63 Write-Verbose -Verbose -Message "Copying $BuildSrcPath/${ModuleName}.pdb to $BuildOutPath"64 Copy-Item -Path "$BuildSrcPath/${ModuleName}.pdb" -Dest "$BuildOutPath"65 }66 }67 catch {68 Write-Verbose -Verbose -Message "dotnet build failed with error: $_"69 Write-Error "dotnet build failed with error: $_"70 }71 finally {72 Pop-Location73 }74 }75 else {76 Write-Verbose -Verbose -Message "No code to build in '${SrcPath}/code'"77 }78 79 ## Add build and packaging here80 Write-Verbose -Verbose -Message "Ending DoBuild"81}82 