Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@RobertWaite
Created January 10, 2023 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobertWaite/0a1cbc8408a1b3a30017fbf3f80094e6 to your computer and use it in GitHub Desktop.
Save RobertWaite/0a1cbc8408a1b3a30017fbf3f80094e6 to your computer and use it in GitHub Desktop.
Save Time Everyday PowerShell Series Part 2 - XML manipulation to automate builds with MSBuild Command Line.
function Initialize-LibFolder
{
param(
[System.IO.FileInfo]$ProjectFolder,
[System.IO.FileInfo]$SourceAcumaticaFolder
)
$sourcePath = "$SourceAcumaticaFolder\bin"
$libFiles = dir "$ProjectFolder\lib\"
foreach($libFile in $libFiles)
{
$destinationFileName = $libFile.Name
$destinationPAth = $libFile.FullName
$sourceFilePath = $sourcePath + "\" + $destinationFileName
copy -Path $sourceFilePath -Destination $destinationPAth
}
}
function Update-VSProjectFile
{
param
($TargetProjectFile,
$TargetVersion,
$TargetAcumaticaInstancePath,
$ConditionalCompilationTags
)
[xml]$ProjectFile = Get-Content -Path $TargetProjectFile
$ProjectFile.Project.PropertyGroup[0].FileVersion = $TargetVersion
$ProjectFile.Project.PropertyGroup[0].InformationalVersion = $TargetVersion
$ProjectFile.Project.PropertyGroup[1].OutputPath = "$TargetAcumaticaInstancePath\Bin\"
$ProjectFile.Project.PropertyGroup[1].DefineConstants = $ConditionalCompilationTags
$ProjectFile.Project.PropertyGroup[2].OutputPath = "$TargetAcumaticaInstancePath\Bin\"
$ProjectFile.Project.PropertyGroup[2].DefineConstants = $ConditionalCompilationTags
$ProjectFile.Save($TargetProjectFile)
}
Function Build-ExtentionLibrary
{
param
(
$SolutionFilePath
)
#$msbuild = "C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
$msbuild = "C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\MSBuild.exe"
$BuildArgs = @("$SolutionFilePath",
"/property:Configuration=Debug",
"/target:Rebuild"
)
$buildResults = & $msbuild $BuildArgs
$isBuildSussessful = $true
foreach($line in $buildResults)
{
if($line.Contains("Build FAILED"))
{
$isBuildSussessful = $false
}
}
if(-not $isBuildSussessful)
{
"----------------------------"
Write-Host "Build Failed" -ForegroundColor Red
Read-Host "The build has failed. The package neends to be Manaully compiled"
Clear
$buildResults
}
else
{
"----------------------------"
Write-Host "Successfully Built Extension Library" -ForegroundColor Green
}
}
$BuildConfigArray = @(
@{
AcumaticaInstancePath = "D:\Acumatica\PSH21_128_0009"
TargetVersion = "21.128.0009"
ConditionalCompilationTags = "A21R1"
},
@{
AcumaticaInstancePath = "D:\Acumatica\PSH21_221_0019"
TargetVersion = "21.221.0019"
ConditionalCompilationTags = "A21R2"
},
@{
AcumaticaInstancePath = "D:\Acumatica\PSH22_117_0016"
TargetVersion = "22.117.0016"
ConditionalCompilationTags = "A22R1"
},
@{
AcumaticaInstancePath = "D:\Acumatica\PSH22_207_0013"
TargetVersion = "22.207.0013"
ConditionalCompilationTags = "A22R2"
}
)
<# uncomment and configure if functions are in seperate files
Import-Module PSH:\MVP\Initialize-LibFolder.ps1
Import-Module PSH:\MVP\Update-VSProjectFile.ps1
Import-Module PSH:\MVP\Build-ExtentionLibrary.ps1
#>
foreach($BuildConfig in $BuildConfigArray)
{
Initialize-LibFolder $VSProjectFolder $BuildConfig.AcumaticaInstancePath
Update-VSProjectFile -TargetProjectFile $TargetProjectFile `
-TargetVersion $BuildConfig.TargetVersion `
-TargetAcumaticaInstancePath $BuildConfig.AcumaticaInstancePath `
-ConditionalCompilationTags $BuildConfig.ConditionalCompilationTags
Build-ExtentionLibrary $TargetSolutionFile
if($PromptForMaualePacakge)
{
# Prompt the user that a package needs to be build. Automating this part will be
#The topic of Part 3 of this PowerShell series.
Read-Host "Package Building is not yet automated. Manual processing is needed to finish the package."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment