Skip to content

Instantly share code, notes, and snippets.

@tcartwright
Created June 2, 2021 20:37
Show Gist options
  • Save tcartwright/cc1bd4dc98349579630c43283c5f1fe9 to your computer and use it in GitHub Desktop.
Save tcartwright/cc1bd4dc98349579630c43283c5f1fe9 to your computer and use it in GitHub Desktop.
VISUAL STUDIO 2017+: Enable large address aware on post build
@rem bat file to ease use of the powershell
@%~d0
@cd "%~dp0"
@REM NOTE: Save the PostBuildEvent.ps1 to your project directory
powershell.exe -ExecutionPolicy Bypass -NoLogo -NoProfile -file "$(ProjectDir)PostBuildEvent.ps1" -TargetPath "$(TargetPath)"
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[string] $TargetPath
)
Clear-Host
# TIM C: I extrapolated how to load vs shell from the shortcut that installs with VS 2019 called: "Developer PowerShell for VS 2019".
# I added the take on VSWHERE so it will work for any version 2017+
#. "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -?
$instance = (. "$(${env:ProgramFiles(x86)})\Microsoft Visual Studio\Installer\vswhere.exe" -latest -format json | ConvertFrom-Json)
$common7Path = ([System.IO.FileInfo]$instance.productPath).Directory.Parent.FullName
$instanceId = $instance.instanceId
Import-Module "$common7Path\Tools\Microsoft.VisualStudio.DevShell.dll";
Enter-VsDevShell $instanceId
Set-Location ([Io.Path]::Combine($common7Path, "..\"))
$path = (get-Location).Path
$editBin = (Get-ChildItem -Path $path -Filter "editbin.exe" -Recurse -File).FullName
if ($editBin) {
"Setting large address aware: `r`n`t'$editBin' /largeaddressaware '$TargetPath'"
. "$editBin" /largeaddressaware "$TargetPath"
} else {
Write-Error "Could not find editbin.exe under path: $path"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment