2024-02-20 20:51:59 -05:00
|
|
|
# This batch file assumes the following:
|
2025-11-24 11:57:17 -05:00
|
|
|
# - .NET 10.0 (or newer) SDK is installed and in PATH
|
2024-02-20 20:51:59 -05:00
|
|
|
# - 7-zip commandline (7z.exe) is installed and in PATH
|
|
|
|
|
# - Git for Windows is installed and in PATH
|
|
|
|
|
#
|
|
|
|
|
# If any of these are not satisfied, the operation may fail
|
|
|
|
|
# in an unpredictable way and result in an incomplete output.
|
|
|
|
|
|
|
|
|
|
# Optional parameters
|
|
|
|
|
param(
|
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
|
|
|
[Alias("UseAll")]
|
|
|
|
|
[switch]$USE_ALL,
|
|
|
|
|
|
2024-12-06 11:52:33 -05:00
|
|
|
[Parameter(Mandatory = $false)]
|
|
|
|
|
[Alias("IncludeDebug")]
|
|
|
|
|
[switch]$INCLUDE_DEBUG,
|
|
|
|
|
|
2024-02-20 20:54:28 -05:00
|
|
|
[Parameter(Mandatory = $false)]
|
2024-02-20 20:51:59 -05:00
|
|
|
[Alias("NoBuild")]
|
|
|
|
|
[switch]$NO_BUILD,
|
|
|
|
|
|
2024-02-20 20:54:28 -05:00
|
|
|
[Parameter(Mandatory = $false)]
|
2024-02-20 20:51:59 -05:00
|
|
|
[Alias("NoArchive")]
|
|
|
|
|
[switch]$NO_ARCHIVE
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Set the current directory as a variable
|
|
|
|
|
$BUILD_FOLDER = $PSScriptRoot
|
|
|
|
|
|
|
|
|
|
# Set the current commit hash
|
|
|
|
|
$COMMIT = git log --pretty=format:"%H" -1
|
|
|
|
|
|
2024-06-26 11:32:20 -04:00
|
|
|
# Output the selected options
|
|
|
|
|
Write-Host "Selected Options:"
|
|
|
|
|
Write-Host " Use all frameworks (-UseAll) $USE_ALL"
|
2024-12-06 11:52:33 -05:00
|
|
|
Write-Host " Include debug builds (-IncludeDebug) $INCLUDE_DEBUG"
|
2024-06-26 11:32:20 -04:00
|
|
|
Write-Host " No build (-NoBuild) $NO_BUILD"
|
|
|
|
|
Write-Host " No archive (-NoArchive) $NO_ARCHIVE"
|
|
|
|
|
Write-Host " "
|
|
|
|
|
|
2024-02-20 20:51:59 -05:00
|
|
|
# Create the build matrix arrays
|
2025-11-24 11:57:17 -05:00
|
|
|
$FRAMEWORKS = @('net10.0')
|
2024-06-26 11:32:20 -04:00
|
|
|
$RUNTIMES = @('win-x86', 'win-x64', 'win-arm64', 'linux-x64', 'linux-arm64', 'osx-x64', 'osx-arm64')
|
2024-02-20 20:51:59 -05:00
|
|
|
|
|
|
|
|
# Use expanded lists, if requested
|
2024-06-26 11:32:20 -04:00
|
|
|
if ($USE_ALL.IsPresent) {
|
2025-11-24 11:57:17 -05:00
|
|
|
$FRAMEWORKS = @('net20', 'net35', 'net40', 'net452', 'net462', 'net472', 'net48', 'netcoreapp3.1', 'net5.0', 'net6.0', 'net7.0', 'net8.0', 'net9.0', 'net10.0')
|
2024-02-20 20:51:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Create the filter arrays
|
2025-11-24 11:57:17 -05:00
|
|
|
$SINGLE_FILE_CAPABLE = @('net5.0', 'net6.0', 'net7.0', 'net8.0', 'net9.0', 'net10.0')
|
|
|
|
|
$VALID_APPLE_FRAMEWORKS = @('net6.0', 'net7.0', 'net8.0', 'net9.0', 'net10.0')
|
|
|
|
|
$VALID_CROSS_PLATFORM_FRAMEWORKS = @('netcoreapp3.1', 'net5.0', 'net6.0', 'net7.0', 'net8.0', 'net9.0', 'net10.0')
|
2024-06-26 12:44:32 -04:00
|
|
|
$VALID_CROSS_PLATFORM_RUNTIMES = @('win-arm64', 'linux-x64', 'linux-arm64', 'osx-x64', 'osx-arm64')
|
2024-02-20 20:51:59 -05:00
|
|
|
|
|
|
|
|
# Only build if requested
|
2024-06-26 11:32:20 -04:00
|
|
|
if (!$NO_BUILD.IsPresent) {
|
2024-02-20 20:54:28 -05:00
|
|
|
# Restore Nuget packages for all builds
|
|
|
|
|
Write-Host "Restoring Nuget packages"
|
|
|
|
|
dotnet restore
|
2024-02-20 20:51:59 -05:00
|
|
|
|
|
|
|
|
# Create Nuget Package
|
2024-02-20 21:04:39 -05:00
|
|
|
dotnet pack BinaryObjectScanner\BinaryObjectScanner.csproj --output $BUILD_FOLDER
|
2024-02-20 20:51:59 -05:00
|
|
|
|
2024-11-04 14:38:23 -05:00
|
|
|
# Build ProtectionScan
|
|
|
|
|
foreach ($FRAMEWORK in $FRAMEWORKS) {
|
|
|
|
|
foreach ($RUNTIME in $RUNTIMES) {
|
|
|
|
|
# Output the current build
|
|
|
|
|
Write-Host "===== Build ProtectionScan - $FRAMEWORK, $RUNTIME ====="
|
|
|
|
|
|
|
|
|
|
# If we have an invalid combination of framework and runtime
|
|
|
|
|
if ($VALID_CROSS_PLATFORM_FRAMEWORKS -notcontains $FRAMEWORK -and $VALID_CROSS_PLATFORM_RUNTIMES -contains $RUNTIME) {
|
|
|
|
|
Write-Host "Skipped due to invalid combination"
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# If we have Apple silicon but an unsupported framework
|
|
|
|
|
if ($VALID_APPLE_FRAMEWORKS -notcontains $FRAMEWORK -and $RUNTIME -eq 'osx-arm64') {
|
|
|
|
|
Write-Host "Skipped due to no Apple Silicon support"
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Only .NET 5 and above can publish to a single file
|
|
|
|
|
if ($SINGLE_FILE_CAPABLE -contains $FRAMEWORK) {
|
2024-12-06 11:52:33 -05:00
|
|
|
# Only include Debug if set
|
|
|
|
|
if ($INCLUDE_DEBUG.IsPresent) {
|
2024-11-04 14:38:23 -05:00
|
|
|
dotnet publish ProtectionScan\ProtectionScan.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT -p:PublishSingleFile=true
|
|
|
|
|
}
|
|
|
|
|
dotnet publish ProtectionScan\ProtectionScan.csproj -f $FRAMEWORK -r $RUNTIME -c Release --self-contained true --version-suffix $COMMIT -p:PublishSingleFile=true -p:DebugType=None -p:DebugSymbols=false
|
|
|
|
|
}
|
|
|
|
|
else {
|
2024-12-06 11:52:33 -05:00
|
|
|
# Only include Debug if set
|
|
|
|
|
if ($INCLUDE_DEBUG.IsPresent) {
|
2024-11-04 14:38:23 -05:00
|
|
|
dotnet publish ProtectionScan\ProtectionScan.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT
|
|
|
|
|
}
|
|
|
|
|
dotnet publish ProtectionScan\ProtectionScan.csproj -f $FRAMEWORK -r $RUNTIME -c Release --self-contained true --version-suffix $COMMIT -p:DebugType=None -p:DebugSymbols=false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-20 20:51:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Only create archives if requested
|
2024-06-26 11:32:20 -04:00
|
|
|
if (!$NO_ARCHIVE.IsPresent) {
|
2024-11-04 14:38:23 -05:00
|
|
|
# Create ProtectionScan archives
|
|
|
|
|
foreach ($FRAMEWORK in $FRAMEWORKS) {
|
|
|
|
|
foreach ($RUNTIME in $RUNTIMES) {
|
|
|
|
|
# Output the current build
|
|
|
|
|
Write-Host "===== Archive ProtectionScan - $FRAMEWORK, $RUNTIME ====="
|
|
|
|
|
|
|
|
|
|
# If we have an invalid combination of framework and runtime
|
|
|
|
|
if ($VALID_CROSS_PLATFORM_FRAMEWORKS -notcontains $FRAMEWORK -and $VALID_CROSS_PLATFORM_RUNTIMES -contains $RUNTIME) {
|
|
|
|
|
Write-Host "Skipped due to invalid combination"
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# If we have Apple silicon but an unsupported framework
|
|
|
|
|
if ($VALID_APPLE_FRAMEWORKS -notcontains $FRAMEWORK -and $RUNTIME -eq 'osx-arm64') {
|
|
|
|
|
Write-Host "Skipped due to no Apple Silicon support"
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-06 11:52:33 -05:00
|
|
|
# Only include Debug if set
|
|
|
|
|
if ($INCLUDE_DEBUG.IsPresent) {
|
2024-11-04 14:38:23 -05:00
|
|
|
Set-Location -Path $BUILD_FOLDER\ProtectionScan\bin\Debug\${FRAMEWORK}\${RUNTIME}\publish\
|
2024-12-18 10:21:06 -05:00
|
|
|
7z a -tzip $BUILD_FOLDER\ProtectionScan_${FRAMEWORK}_${RUNTIME}_debug.zip *
|
2024-11-04 14:38:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Set-Location -Path $BUILD_FOLDER\ProtectionScan\bin\Release\${FRAMEWORK}\${RUNTIME}\publish\
|
2024-12-18 10:21:06 -05:00
|
|
|
7z a -tzip $BUILD_FOLDER\ProtectionScan_${FRAMEWORK}_${RUNTIME}_release.zip *
|
2024-11-04 14:38:23 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-20 20:54:28 -05:00
|
|
|
# Reset the directory
|
|
|
|
|
Set-Location -Path $PSScriptRoot
|
2024-02-20 20:51:59 -05:00
|
|
|
}
|