Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b0e29e0a3 | ||
|
|
ba5120b9de | ||
|
|
1449bb059b |
@@ -0,0 +1,45 @@
|
||||
# Windows Collect Dependencies
|
||||
|
||||
A small Gitea Action for collecting the non-system DLL dependencies required by a Windows executable.
|
||||
|
||||
The action uses `dumpbin` to recursively find dependencies and copies the required DLLs into an artifact directory while skipping Windows system libraries.
|
||||
|
||||
## Usage
|
||||
|
||||
```yaml
|
||||
- name: Collect dependencies
|
||||
uses: https://git.omgitsalexl.me/omgitsalexl/windows-collect-dependencies@v1.0.3
|
||||
with:
|
||||
executable: path/to/MyApp.exe
|
||||
output: artifacts
|
||||
```
|
||||
|
||||
### Inputs
|
||||
|
||||
| Input | Required | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| `executable` | Yes | | Path to the executable to inspect |
|
||||
| `output` | No | `artifacts` | Directory where dependencies are copied |
|
||||
|
||||
The executable itself is not copied. Add it to the output directory separately if you want to package it with the collected DLLs.
|
||||
|
||||
## Requirements
|
||||
|
||||
The Windows runner must have Visual Studio or Visual Studio Build Tools installed with the **MSVC C++ tools**.
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
- name: Copy executable
|
||||
shell: powershell
|
||||
run: |
|
||||
New-Item -ItemType Directory -Force -Path artifacts
|
||||
Copy-Item "build\MyApp.exe" "artifacts\MyApp.exe"
|
||||
|
||||
- name: Collect dependencies
|
||||
uses: https://git.omgitsalexl.me/omgitsalexl/windows-collect-dependencies@v1.0.3
|
||||
with:
|
||||
executable: build/MyApp.exe
|
||||
```
|
||||
|
||||
The resulting `artifacts` directory can then be uploaded or packaged by the rest of your workflow.
|
||||
+62
-2
@@ -14,12 +14,55 @@ if (-not (Test-Path $Executable)) {
|
||||
|
||||
New-Item -ItemType Directory -Force -Path $Output | Out-Null
|
||||
|
||||
$vswherePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
|
||||
|
||||
if (-not (Test-Path $vswherePath)) {
|
||||
throw "Could not locate vswhere.exe. Verify that Visual Studio or Visual Studio Build Tools is installed."
|
||||
}
|
||||
|
||||
$visualStudioPath = & $vswherePath `
|
||||
-latest `
|
||||
-products * `
|
||||
-requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 `
|
||||
-property installationPath
|
||||
|
||||
if (-not $visualStudioPath) {
|
||||
throw "Could not locate a Visual Studio installation with the MSVC C++ tools installed."
|
||||
}
|
||||
|
||||
$toolsetVersionPath = Join-Path `
|
||||
$visualStudioPath `
|
||||
"VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt"
|
||||
|
||||
if (-not (Test-Path $toolsetVersionPath)) {
|
||||
throw "Could not locate the MSVC toolset version file."
|
||||
}
|
||||
|
||||
$toolsetVersion = (Get-Content $toolsetVersionPath -Raw).Trim()
|
||||
|
||||
$dumpbinPath = Join-Path `
|
||||
$visualStudioPath `
|
||||
"VC\Tools\MSVC\$toolsetVersion\bin\Hostx64\x64\dumpbin.exe"
|
||||
|
||||
if (-not (Test-Path $dumpbinPath)) {
|
||||
throw "Could not locate dumpbin.exe at: $dumpbinPath"
|
||||
}
|
||||
|
||||
Write-Host "Using dumpbin: $dumpbinPath"
|
||||
|
||||
$windowsDirectories = @(
|
||||
$env:WINDIR,
|
||||
(Join-Path $env:WINDIR "System32"),
|
||||
(Join-Path $env:WINDIR "SysWOW64")
|
||||
)
|
||||
|
||||
$windowsKitsDirectories = @(
|
||||
"${env:ProgramFiles(x86)}\Windows Kits",
|
||||
"$env:ProgramFiles\Windows Kits"
|
||||
) | Where-Object {
|
||||
$_ -and (Test-Path $_)
|
||||
}
|
||||
|
||||
$processed = @{}
|
||||
|
||||
function Test-IsWindowsSystemDll {
|
||||
@@ -27,6 +70,10 @@ function Test-IsWindowsSystemDll {
|
||||
[string]$Name
|
||||
)
|
||||
|
||||
if ($Name -like "api-ms-win-*.dll") {
|
||||
return $true
|
||||
}
|
||||
|
||||
foreach ($directory in $windowsDirectories) {
|
||||
$path = Join-Path $directory $Name
|
||||
|
||||
@@ -35,6 +82,20 @@ function Test-IsWindowsSystemDll {
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($directory in $windowsKitsDirectories) {
|
||||
$match = Get-ChildItem `
|
||||
-Path $directory `
|
||||
-Filter $Name `
|
||||
-File `
|
||||
-Recurse `
|
||||
-ErrorAction SilentlyContinue |
|
||||
Select-Object -First 1
|
||||
|
||||
if ($match) {
|
||||
return $true
|
||||
}
|
||||
}
|
||||
|
||||
return $false
|
||||
}
|
||||
|
||||
@@ -66,13 +127,12 @@ function Copy-Dependencies {
|
||||
|
||||
$binaryDirectory = Split-Path -Parent $Binary
|
||||
|
||||
$dependencies = dumpbin /DEPENDENTS $Binary |
|
||||
$dependencies = & $dumpbinPath /DEPENDENTS $Binary |
|
||||
Select-String '^\s+.*\.dll$' |
|
||||
ForEach-Object { $_.Line.Trim() } |
|
||||
Sort-Object -Unique
|
||||
|
||||
foreach ($dll in $dependencies) {
|
||||
|
||||
$key = $dll.ToLowerInvariant()
|
||||
|
||||
if ($processed.ContainsKey($key)) {
|
||||
|
||||
Reference in New Issue
Block a user