-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild-ContextMenuHandler.ps1
More file actions
155 lines (126 loc) · 4.55 KB
/
Build-ContextMenuHandler.ps1
File metadata and controls
155 lines (126 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#Requires -Version 5.1
<#
.SYNOPSIS
Builds MsixContextMenuHandler.dll with VS Build Tools 2022 (Release|x64).
.PARAMETER Configuration
Build configuration. Default: Release.
.PARAMETER Clean
Run a clean build (msbuild /t:Clean,Build).
#>
param(
[ValidateSet('Release', 'Debug')]
[string] $Configuration = 'Release',
[switch] $Clean
)
Set-StrictMode -Version 2.0
$ErrorActionPreference = 'Stop'
# ---------------------------------------------------------------------------
# Locate MSBuild via vswhere
# ---------------------------------------------------------------------------
$vswhere = Join-Path ${env:ProgramFiles(x86)} `
'Microsoft Visual Studio\Installer\vswhere.exe'
if (-not (Test-Path $vswhere)) {
Write-Error "vswhere.exe not found at: $vswhere`nMake sure VS Build Tools 2022 are installed."
exit 1
}
$msbuildPath = & $vswhere `
-latest `
-products '*' `
-requires Microsoft.Component.MSBuild `
-find 'MSBuild\**\Bin\MSBuild.exe' |
Select-Object -First 1
if (-not $msbuildPath -or -not (Test-Path $msbuildPath)) {
Write-Error "MSBuild.exe not found. Install the 'MSBuild' component in VS Build Tools 2022."
exit 1
}
Write-Verbose "MSBuild: $msbuildPath"
# ---------------------------------------------------------------------------
# Version — increment patch, regenerate src\version.rc
# ---------------------------------------------------------------------------
$versionFile = Join-Path $PSScriptRoot 'version.txt'
$versionRc = Join-Path $PSScriptRoot 'src\version.rc'
$raw = (Get-Content $versionFile -Raw).Trim()
$parts = $raw -split '\.'
if ($parts.Count -lt 3) { $parts = @('0','9','0') }
$major = [int]$parts[0]
$minor = [int]$parts[1]
$patch = [int]$parts[2] + 1
$version = "$($major).$($minor).$($patch)"
$versionFull = "$($major).$($minor).$($patch).0"
$versionRes = "$($major),$($minor),$($patch),0"
Set-Content -Path $versionFile -Value $version -Encoding UTF8
Write-Output "Version: $versionFull"
$rcContent = @"
// Generated by Build-ContextMenuHandler.ps1 -- do not edit manually.
#include <windows.h>
VS_VERSION_INFO VERSIONINFO
FILEVERSION $versionRes
PRODUCTVERSION $versionRes
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "MSIXForcelets"
VALUE "FileDescription", "MSIX Context Menu Handler Shell Extension"
VALUE "FileVersion", "$versionFull"
VALUE "InternalName", "MsixContextMenuHandler"
VALUE "LegalCopyright", "Copyright 2025 Andreas Nick"
VALUE "OriginalFilename", "MsixContextMenuHandler.dll"
VALUE "ProductName", "MsixContextMenuHandler"
VALUE "ProductVersion", "$versionFull"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
"@
[IO.File]::WriteAllText($versionRc, $rcContent, [Text.Encoding]::UTF8)
# ---------------------------------------------------------------------------
# Build
# ---------------------------------------------------------------------------
$sln = Join-Path $PSScriptRoot 'MsixContextMenuHandler.sln'
$target = if ($Clean) { 'Clean;Build' } else { 'Build' }
$msbuildArgs = @(
$sln
"/t:$target"
"/p:Configuration=$Configuration"
'/p:Platform=x64'
'/nologo'
'/verbosity:minimal'
)
Write-Output "Building $Configuration|x64 ..."
& $msbuildPath @msbuildArgs
if ($LASTEXITCODE -ne 0) {
Write-Error "Build failed (exit $LASTEXITCODE)."
exit $LASTEXITCODE
}
$dll = Join-Path $PSScriptRoot "bin\$Configuration\MsixContextMenuHandler.dll"
$testDir = Join-Path $PSScriptRoot 'Test'
if (-not (Test-Path $dll)) {
Write-Warning "MSBuild reported success but DLL not found at: $dll"
exit 1
}
Write-Output "Build succeeded. Version: $versionFull"
Write-Output "Output: $dll"
# ---------------------------------------------------------------------------
# Copy DLL and all test-support files to Test\
# ---------------------------------------------------------------------------
Copy-Item -Path $dll -Destination $testDir -Force
Write-Output "Copied DLL to: $testDir"
Write-Output ""
Write-Output "Next steps for outside-MSIX testing:"
Write-Output " 1. Place the target executable (e.g. WinRAR.exe) in: $testDir"
Write-Output " 2. Run Test\Install-ContextMenuHandler.ps1 [-RestartExplorer]"
Write-Output " The JSON uses relative paths - resolved against the DLL directory."