1
+ # PowerShell < 7 does not handle ZIP files correctly.
2
+ if ($PSVersionTable.PSVersion.Major -lt 7 ) {
3
+ throw " This script requires PowerShell 7 or higher."
4
+ }
5
+
6
+ $rootDir = $MyInvocation.MyCommand.Path
7
+
8
+ if (! $rootDir ) {
9
+ $rootDir = $psISE.CurrentFile.Fullpath
10
+ }
11
+
12
+ if ($rootDir ) {
13
+ foreach ($i in 1 .. 2 ) {
14
+ $rootDir = Split-Path $rootDir - Parent
15
+ }
16
+ }
17
+ else {
18
+ throw ' Could not determine root directory of project.'
19
+ }
20
+
21
+ if (! [bool ](Get-Command - ErrorAction Stop - Type Application dotnet)) {
22
+ throw ' dotnet SDK could not be found.'
23
+ }
24
+
25
+ $winKitDir = Get-ItemPropertyValue ' HKLM:\SOFTWARE\Microsoft\Windows Kits\Installed Roots' ' KitsRoot10'
26
+
27
+ if (! $winKitDir -or ! (Test-Path - Path $winKitDir )) {
28
+ throw ' Windows SDK path is not found.'
29
+ }
30
+
31
+ $sdkVersion = Get-ChildItem - Path ' HKLM:\SOFTWARE\Microsoft\Windows Kits\Installed Roots' | Sort-Object Name - Descending | Select-Object - ExpandProperty PSChildName - First 1
32
+ $sdkPath = Join-Path - Path $winKitDir - ChildPath ' bin'
33
+ $sdkPath = Join-Path - Path $sdkPath - ChildPath $sdkVersion
34
+
35
+ $architecture = [System.Environment ]::GetEnvironmentVariable(" PROCESSOR_ARCHITECTURE" )
36
+ $archDirName = switch ($architecture ) {
37
+ ' ARM64' { ' arm64' }
38
+ ' x86' { ' x86' }
39
+ ' AMD64' { ' x64' }
40
+ Default { throw ' Unknown architecture' }
41
+ }
42
+
43
+ $sdkBinPath = Join-Path - Path $sdkPath - ChildPath $archDirName
44
+ $objDir = Join-Path - Path $rootDir - ChildPath ' obj'
45
+ $outDir = Join-Path - Path $rootDir - ChildPath ' out'
46
+
47
+ pushd $rootDir
48
+
49
+ Remove-Item - Path $objDir - Recurse - Force - ErrorAction SilentlyContinue
50
+ New-Item - Path $objDir - ItemType Directory
51
+
52
+ Remove-Item - Path $outDir - Recurse - Force - ErrorAction SilentlyContinue
53
+ New-Item - Path $outDir - ItemType Directory
54
+
55
+ dotnet pack - p:OutputFileNamesWithoutVersion= true - p:ContinuousIntegrationBuild= true - c Release - o $objDir src\AuthenticodeExaminer\AuthenticodeExaminer.csproj
56
+
57
+ Expand-Archive - Path $objDir \AuthenticodeExaminer.nupkg - DestinationPath $objDir \AuthenticodeExaminer.nupkg.dir
58
+
59
+ Remove-Item - Path $objDir \AuthenticodeExaminer.nupkg
60
+
61
+ & " $sdkBinPath \signtool.exe" sign / d " AuthenticodeExaminer" / sha1 73f0844a95e35441a676cd6be1e79a3cd51d00b4 / fd SHA384 / td SHA384 / tr " http://timestamp.digicert.com" / du " https://github.com/vcsjones/AuthenticodeExaminer" " $objDir \AuthenticodeExaminer.nupkg.dir\lib\netstandard2.0\AuthenticodeExaminer.dll"
62
+ & " $sdkBinPath \signtool.exe" sign / d " AuthenticodeExaminer" / sha1 73f0844a95e35441a676cd6be1e79a3cd51d00b4 / fd SHA384 / td SHA384 / tr " http://timestamp.digicert.com" / du " https://github.com/vcsjones/AuthenticodeExaminer" " $objDir \AuthenticodeExaminer.nupkg.dir\lib\net462\AuthenticodeExaminer.dll"
63
+
64
+ Compress-Archive - Path " $objDir \AuthenticodeExaminer.nupkg.dir\*" - DestinationPath " $objDir \AuthenticodeExaminer.nupkg"
65
+
66
+ dotnet nuget sign -- certificate- fingerprint 68821304869e065c24e0684eb43bf974e124642f3437f2ff494a93bb371d029a -- hash- algorithm SHA384 -- timestamper " http://timestamp.digicert.com" -- overwrite " $objDir \AuthenticodeExaminer.nupkg"
67
+
68
+ Copy-Item - Path " $objDir \AuthenticodeExaminer.nupkg" - Destination " $outDir \AuthenticodeExaminer.nupkg"
69
+
70
+ popd
0 commit comments