Skip to content

Instantly share code, notes, and snippets.

@brcha
Created May 22, 2024 01:51
Show Gist options
  • Save brcha/def9f762f823ce6be465439f055819b1 to your computer and use it in GitHub Desktop.
Save brcha/def9f762f823ce6be465439f055819b1 to your computer and use it in GitHub Desktop.
vcvars.ps1
# Allow executing CMD scripts
function Invoke-CmdScript {
param(
[String] $scriptName
)
$cmdLine = """$scriptName"" $args & set"
& $Env:SystemRoot\system32\cmd.exe /c $cmdLine |
select-string '^([^=]*)=(.*)$' | foreach-object {
$varName = $_.Matches[0].Groups[1].Value
$varValue = $_.Matches[0].Groups[2].Value
set-item Env:$varName $varValue
}
}
# Generic function that set Visual Studio variables to newest versions
function VcVarsAll {
param(
[String] $arch = "x64",
[String] $sdk = "10.0.22000.0",
[String] $vcvars = "14.31"
)
Invoke-CmdScript 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat' $arch $sdk "-vcvars_ver=$vcvars"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment