From 39c36592631e6f6376c404a83ef2d562358d0db7 Mon Sep 17 00:00:00 2001 From: Kevin Jones Date: Wed, 25 Sep 2024 14:25:11 -0400 Subject: [PATCH] Build stuff --- build/build.proj | 54 ----------------------------- build/build.ps1 | 90 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 54 deletions(-) delete mode 100644 build/build.proj create mode 100644 build/build.ps1 diff --git a/build/build.proj b/build/build.proj deleted file mode 100644 index 81d3f2c..0000000 --- a/build/build.proj +++ /dev/null @@ -1,54 +0,0 @@ - - - - AzureSignTool - https://vcsjones.com/azuresigntool - Kevin Jones - - - $(MSBuildThisFileDirectory)..\out\ - $(OutputDir)AzureSignTool.zip - - - - - OutputPath=$(OutputDir);Configuration=Release - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/build/build.ps1 b/build/build.ps1 new file mode 100644 index 0000000..db6042d --- /dev/null +++ b/build/build.ps1 @@ -0,0 +1,90 @@ +# PowerShell < 7 does not handle ZIP files correctly. +if ($PSVersionTable.PSVersion.Major -lt 7) { + throw "This script requires PowerShell 7 or higher." +} + +$rootDir = $MyInvocation.MyCommand.Path + +if (!$rootDir) { + $rootDir = $psISE.CurrentFile.Fullpath +} + +if ($rootDir) { + foreach($i in 1..2) { + $rootDir = Split-Path $rootDir -Parent + } +} +else { + throw 'Could not determine root directory of project.' +} + +if (![bool](Get-Command -ErrorAction Stop -Type Application dotnet)) { + throw 'dotnet SDK could not be found.' +} + +$winKitDir = Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows Kits\Installed Roots' 'KitsRoot10' + +if (!$winKitDir -or !(Test-Path -Path $winKitDir)) { + throw 'Windows SDK path is not found.' +} + +$sdkVersion = Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\Windows Kits\Installed Roots' | Sort-Object Name -Descending | Select-Object -ExpandProperty PSChildName -First 1 +$sdkPath = Join-Path -Path $winKitDir -ChildPath 'bin' +$sdkPath = Join-Path -Path $sdkPath -ChildPath $sdkVersion + +$architecture = [System.Environment]::GetEnvironmentVariable("PROCESSOR_ARCHITECTURE") +$archDirName = switch ($architecture) { + 'ARM64' { 'arm64' } + 'x86' { 'x86' } + 'AMD64' { 'x64' } + Default { throw 'Unknown architecture' } +} + +$sdkBinPath = Join-Path -Path $sdkPath -ChildPath $archDirName +$objDir = Join-Path -Path $rootDir -ChildPath 'obj' +$outDir = Join-Path -Path $rootDir -ChildPath 'out' + +pushd $rootDir + +Remove-Item -Path $objDir -Recurse -Force -ErrorAction SilentlyContinue +New-Item -Path $objDir -ItemType Directory + +Remove-Item -Path $outDir -Recurse -Force -ErrorAction SilentlyContinue +New-Item -Path $outDir -ItemType Directory + +dotnet pack -p:OutputFileNamesWithoutVersion=true -c Release -o $objDir src\AzureSign.Core\AzureSign.Core.csproj +dotnet pack -p:OutputFileNamesWithoutVersion=true -c Release -o $objDir src\AzureSignTool\AzureSignTool.csproj + +Expand-Archive -Path $objDir\AzureSign.Core.nupkg -DestinationPath $objDir\AzureSign.Core.nupkg.dir +Expand-Archive -Path $objDir\AzureSignTool.nupkg -DestinationPath $objDir\AzureSignTool.nupkg.dir + +Remove-Item -Path $objDir\AzureSign.Core.nupkg +Remove-Item -Path $objDir\AzureSignTool.nupkg + +$commonSignArgs = + +& "$sdkBinPath\signtool.exe" sign /d "AzureSign.Core" /sha1 73f0844a95e35441a676cd6be1e79a3cd51d00b4 /fd SHA384 /td SHA384 /tr "http://timestamp.digicert.com" /du "https://github.com/vcsjones/AzureSignTool" "$objDir\AzureSign.Core.nupkg.dir\lib\net8.0\AzureSign.Core.dll" +& "$sdkBinPath\signtool.exe" sign /d "AzureSign.Core" /sha1 73f0844a95e35441a676cd6be1e79a3cd51d00b4 /fd SHA384 /td SHA384 /tr "http://timestamp.digicert.com" /du "https://github.com/vcsjones/AzureSignTool" "$objDir\AzureSign.Core.nupkg.dir\lib\netstandard2.0\AzureSign.Core.dll" +& "$sdkBinPath\signtool.exe" sign /d "AzureSignTool" /sha1 73f0844a95e35441a676cd6be1e79a3cd51d00b4 /fd SHA384 /td SHA384 /tr "http://timestamp.digicert.com" /du "https://github.com/vcsjones/AzureSignTool" "$objDir\AzureSignTool.nupkg.dir\tools\net8.0\any\AzureSignTool.dll" + +Copy-Item -Path "$objDir\AzureSign.Core.nupkg.dir\lib\net8.0\AzureSign.Core.dll" -Destination "$objDir\AzureSignTool.nupkg.dir\tools\net8.0\any\AzureSign.Core.dll" + +Compress-Archive -Path "$objDir\AzureSign.Core.nupkg.dir\*" -DestinationPath "$objDir\AzureSign.Core.nupkg" +Compress-Archive -Path "$objDir\AzureSignTool.nupkg.dir\*" -DestinationPath "$objDir\AzureSignTool.nupkg" + +dotnet nuget sign --certificate-fingerprint 73f0844a95e35441a676cd6be1e79a3cd51d00b4 --hash-algorithm SHA384 --timestamper "http://timestamp.digicert.com" --overwrite "$objDir\AzureSign.Core.nupkg" +dotnet nuget sign --certificate-fingerprint 73f0844a95e35441a676cd6be1e79a3cd51d00b4 --hash-algorithm SHA384 --timestamper "http://timestamp.digicert.com" --overwrite "$objDir\AzureSignTool.nupkg" + +Copy-Item -Path "$objDir\AzureSign.Core.nupkg" -Destination "$outDir\AzureSign.Core.nupkg" +Copy-Item -Path "$objDir\AzureSignTool.nupkg" -Destination "$outDir\AzureSignTool.nupkg" + +dotnet publish -c Release -r win-arm64 -o "$objDir\AzureSignTool-arm64" .\src\AzureSignTool\AzureSignTool.csproj +dotnet publish -c Release -r win-x64 -o "$objDir\AzureSignTool-x64" .\src\AzureSignTool\AzureSignTool.csproj + +& "$sdkBinPath\signtool.exe" sign /d "AzureSignTool" /sha1 73f0844a95e35441a676cd6be1e79a3cd51d00b4 /fd SHA384 /td SHA384 /tr "http://timestamp.digicert.com" /du "https://github.com/vcsjones/AzureSignTool" "$objDir\AzureSignTool-x64\AzureSignTool.exe" +& "$sdkBinPath\signtool.exe" sign /d "AzureSignTool" /sha1 73f0844a95e35441a676cd6be1e79a3cd51d00b4 /fd SHA384 /td SHA384 /tr "http://timestamp.digicert.com" /du "https://github.com/vcsjones/AzureSignTool" "$objDir\AzureSignTool-arm64\AzureSignTool.exe" + +Copy-Item -Path "$objDir\AzureSignTool-x64\AzureSignTool.exe" -Destination "$outDir\AzureSignTool-x64.exe" +Copy-Item -Path "$objDir\AzureSignTool-arm64\AzureSignTool.exe" -Destination "$outDir\AzureSignTool-arm64.exe" + +popd \ No newline at end of file