.DESCRIPTION
Implement build and packaging of the package and place the output $OutDirectory/$ModuleName
#>
function DoBuild
{
Write-Verbose -Verbose -Message "Starting DoBuild with configuration: $BuildConfiguration, framework: $BuildFramework"
$BuildOutPath = "${OutDirectory}/${ModuleName}"
Write-Verbose -Verbose -Message "Module output file path: '$BuildOutPath'"
$BuildSrcPath = "bin/${BuildConfiguration}/${BuildFramework}/publish"
Write-Verbose -Verbose -Message "Module build source path: '$BuildSrcPath'"
Write-Verbose -Verbose "Copy-Item ${SrcPath}/${ModuleName}.psd1 to ${OutDirectory}/${ModuleName}"
Copy-Item "${SrcPath}/${ModuleName}.psd1" "${OutDirectory}/${ModuleName}"
if ( Test-Path "${SrcPath}/code" ) {
Write-Verbose -Verbose -Message "Building assembly and copying to '$BuildOutPath'"
Push-Location "${SrcPath}/code"
try {
$dotnetCommand = Get-Command -Name 'dotnet' -ErrorAction Ignore
if ($null -eq $dotnetCommand) {
Write-Verbose -Verbose -Message "dotnet.exe cannot be found in current path. Looking in ProgramFiles path."
$dotnetCommandPath = Join-Path -Path $env:ProgramFiles -ChildPath "dotnet\dotnet.exe"
$dotnetCommand = Get-Command -Name $dotnetCommandPath -ErrorAction Ignore
if ($null -eq $dotnetCommand) {
throw "Dotnet.exe cannot be found: $dotnetCommandPath is unavailable for build."
}
}
Write-Verbose -Verbose -Message "dotnet.exe command found in path: $($dotnetCommand.Path)"
Write-Verbose -Verbose -Message "DotNet version: $(& ($dotnetCommand) --version)"
Write-Verbose -Verbose -Message "Building with configuration: $BuildConfiguration, framework: $BuildFramework"
Write-Verbose -Verbose -Message "Building location: PSScriptRoot: $PSScriptRoot, PWD: $pwd"
& ($dotnetCommand) publish --configuration $BuildConfiguration --framework $BuildFramework --output $BuildSrcPath
if (! (Test-Path -Path "$BuildSrcPath/${ModuleName}.dll"))
{
throw "Expected binary was not created: $BuildSrcPath/${ModuleName}.dll"
}
Write-Verbose -Verbose -Message "Copying $BuildSrcPath/${ModuleName}.dll to $BuildOutPath"
Copy-Item -Path "$BuildSrcPath/${ModuleName}.dll" -Dest "$BuildOutPath"
if (Test-Path -Path "$BuildSrcPath/${ModuleName}.pdb")
{
Write-Verbose -Verbose -Message "Copying $BuildSrcPath/${ModuleName}.pdb to $BuildOutPath"
Copy-Item -Path "$BuildSrcPath/${ModuleName}.pdb" -Dest "$BuildOutPath"
}
}
catch {
Write-Verbose -Verbose -Message "dotnet build failed with error: $_"
Write-Error "dotnet build failed with error: $_"
}
finally {
Pop-Location
}
}
else {
Write-Verbose -Verbose -Message "No code to build in '${SrcPath}/code'"
}
Write-Verbose -Verbose -Message "Ending DoBuild"
}