Data-Oriented-House / PortableBuildTools

Portable VS Build Tools installer
500 stars 16 forks source link

Create PowerShell environment script as well. #6

Open JeffMill opened 3 months ago

JeffMill commented 3 months ago

Example file:

$installPath='e:\BuildTools'

$env:WindowsSDKDir="$installPath\Windows Kits\10"
$env:WindowsSDKVersion='10.0.22621.0'
$env:VCToolsInstallDir="$installPath\VC\Tools\MSVC\14.39.33519"
$env:VSCMD_ARG_TGT_ARCH='x64'

$env:MSVC_BIN="$env:VCToolsInstallDir\bin\Hostx64\$env:VSCMD_ARG_TGT_ARCH"
$env:SDK_BIN="$env:WindowsSDKDir\bin\$env:WindowsSDKVersion\$env:VSCMD_ARG_TGT_ARCH;$env:WindowsSDKDir\bin\$env:WindowsSDKVersion\$env:VSCMD_ARG_TGT_ARCH\ucrt"

$env:PATH="$env:MSVC_BIN;$env:SDK_BIN;$env:PATH"
$env:INCLUDE="$env:VCToolsInstallDir\include;$env:WindowsSDKDir\Include\$env:WindowsSDKVersion\ucrt;$env:WindowsSDKDir\Include\$env:WindowsSDKVersion\shared;$env:WindowsSDKDir\Include\$env:WindowsSDKVersion\um;$env:WindowsSDKDir\Include\$env:WindowsSDKVersion\winrt;$env:WindowsSDKDir\Include\$env:WindowsSDKVersion\cppwinrt"
$env:LIB="$env:VCToolsInstallDir\lib\$env:VSCMD_ARG_TGT_ARCH;$env:WindowsSDKDir\Lib\$env:WindowsSDKVersion\ucrt\$env:VSCMD_ARG_TGT_ARCH;$env:WindowsSDKDir\Lib\$env:WindowsSDKVersion\um\$env:VSCMD_ARG_TGT_ARCH"
milnak commented 1 month ago

Update, allowing for folder to specified, or implied from script location:

# Folder where PortableDevTools were installed.
Param([string]$InstallPath=$PSScriptRoot)

$env:WindowsSDKDir="$InstallPath\Windows Kits\10"
$env:WindowsSDKVersion='10.0.22621.0'
$env:VCToolsInstallDir="$InstallPath\VC\Tools\MSVC\14.39.33519"
$env:VSCMD_ARG_TGT_ARCH='x64'

$env:MSVC_BIN="$env:VCToolsInstallDir\bin\Hostx64\$env:VSCMD_ARG_TGT_ARCH"
$env:SDK_BIN="$env:WindowsSDKDir\bin\$env:WindowsSDKVersion\$env:VSCMD_ARG_TGT_ARCH;$env:WindowsSDKDir\bin\$env:WindowsSDKVersion\$env:VSCMD_ARG_TGT_ARCH\ucrt"

$env:PATH="$env:MSVC_BIN;$env:SDK_BIN;$env:PATH"
$env:INCLUDE="$env:VCToolsInstallDir\include;$env:WindowsSDKDir\Include\$env:WindowsSDKVersion\ucrt;$env:WindowsSDKDir\Include\$env:WindowsSDKVersion\shared;$env:WindowsSDKDir\Include\$env:WindowsSDKVersion\um;$env:WindowsSDKDir\Include\$env:WindowsSDKVersion\winrt;$env:WindowsSDKDir\Include\$env:WindowsSDKVersion\cppwinrt"
$env:LIB="$env:VCToolsInstallDir\lib\$env:VSCMD_ARG_TGT_ARCH;$env:WindowsSDKDir\Lib\$env:WindowsSDKVersion\ucrt\$env:VSCMD_ARG_TGT_ARCH;$env:WindowsSDKDir\Lib\$env:WindowsSDKVersion\um\$env:VSCMD_ARG_TGT_ARCH"
milnak commented 1 week ago

Another update -- versions are determined from install paths. See my scoop bucket for the latest version.

j-begin commented 1 week ago

@milnak please look at the latest version, how it creates a .bat script, and please send me a .ps1 equivalent, and I will add it in the next release.

Thank you.

milnak commented 2 days ago

Latest version of my script (for 2.2):

# Folder where PortableDevTools were installed.
param([string]$InstallPath = 'c:\BuildTools')

$env:BUILD_TOOLS_ROOT = $InstallPath

$env:WindowsSDKDir = (Join-Path $InstallPath '\Windows Kits\10')
$env:WindowsSDKVersion = (Get-ChildItem -Directory (Join-Path $env:WindowsSDKDir 'bin') -ErrorAction SilentlyContinue | Sort-Object -Descending LastWriteTime | Select-Object -First 1).Name
if (!$env:WindowsSDKVersion ) { throw 'WindowsSDKVersion cannot be determined.' }

$VCToolsVersion = (Get-ChildItem -Directory (Join-Path $InstallPath '\VC\Tools\MSVC' | Sort-Object -Descending LastWriteTime | Select-Object -First 1) -ErrorAction SilentlyContinue).Name
if (!$VCToolsVersion) { throw 'VCToolsVersion cannot be determined.' }
$env:VCToolsInstallDir = Join-Path $InstallPath '\VC\Tools\MSVC' $VCToolsVersion

$env:VSCMD_ARG_TGT_ARCH = 'x64'
$env:VSCMD_ARG_HOST_ARCH = 'x64'

'Portable Build Tools environment started.'
'* WindowsSDKDir      : {0}' -f $env:WindowsSDKDir
'* WindowsSDKVersion  : {0}' -f $env:WindowsSDKVersion
'* VCToolsInstallDir  : {0}' -f $env:VCToolsInstallDir
'* VSCMD_ARG_TGT_ARCH : {0}' -f $env:VSCMD_ARG_TGT_ARCH
'* VSCMD_ARG_HOST_ARCH: {0}' -f $env:VSCMD_ARG_HOST_ARCH

$env:INCLUDE = "$env:VCToolsInstallDir\include;$env:WindowsSDKDir\Include\$env:WindowsSDKVersion\ucrt;$env:WindowsSDKDir\Include\$env:WindowsSDKVersion\shared;$env:WindowsSDKDir\Include\$env:WindowsSDKVersion\um;$env:WindowsSDKDir\Include\$env:WindowsSDKVersion\winrt;$env:WindowsSDKDir\Include\$env:WindowsSDKVersion\cppwinrt"
$env:LIB = "$env:VCToolsInstallDir\lib\$env:VSCMD_ARG_TGT_ARCH;$env:WindowsSDKDir\Lib\$env:WindowsSDKVersion\ucrt\$env:VSCMD_ARG_TGT_ARCH;$env:WindowsSDKDir\Lib\$env:WindowsSDKVersion\um\$env:VSCMD_ARG_TGT_ARCH"
$env:BUILD_TOOLS_BIN = "$env:VCToolsInstallDir\bin\Hostx64\$env:VSCMD_ARG_TGT_ARCH;$env:WindowsSDKDir\bin\$env:WindowsSDKVersion\$env:VSCMD_ARG_TGT_ARCH;$env:WindowsSDKDir\bin\$env:WindowsSDKVersion\$env:VSCMD_ARG_TGT_ARCH\ucrt"
$env:PATH = "$env:BUILD_TOOLS_BIN;$env:PATH"
munohikari commented 2 days ago

@milnak why is it not $PSScriptRoot but a hard-coded path?

milnak commented 2 days ago

I could change it but the assumption is that this script might not be in the root of the install. Feel free to make any modifications you deem necessary

munohikari commented 2 days ago

The script will always be in the root of the install, unless you modify it yourself. I cannot make modifications as i do not know PowerShell at all, so please look at how current .bat script does it, and just do the same in PS.

milnak commented 2 days ago

This now makes default InstallPath the folder this script is in. Note that this script assumes x64 TGT ARCH and HOST ARCH. I can make those parameters as well if desirable.

Can override with e.g. .\devcmd.ps1 -InstallPath D:\BuildTools

# Folder where PortableDevTools were installed.
param([string]$InstallPath = $PSScriptRoot)

$env:BUILD_TOOLS_ROOT = $InstallPath

$env:WindowsSDKDir = (Join-Path $InstallPath '\Windows Kits\10')
$env:WindowsSDKVersion = (Get-ChildItem -Directory (Join-Path $env:WindowsSDKDir 'bin') -ErrorAction SilentlyContinue | Sort-Object -Descending LastWriteTime | Select-Object -First 1).Name
if (!$env:WindowsSDKVersion ) { throw 'WindowsSDKVersion cannot be determined.' }

$VCToolsVersion = (Get-ChildItem -Directory (Join-Path $InstallPath '\VC\Tools\MSVC' | Sort-Object -Descending LastWriteTime | Select-Object -First 1) -ErrorAction SilentlyContinue).Name
if (!$VCToolsVersion) { throw 'VCToolsVersion cannot be determined.' }
$env:VCToolsInstallDir = Join-Path $InstallPath '\VC\Tools\MSVC' $VCToolsVersion

$env:VSCMD_ARG_TGT_ARCH = 'x64'
$env:VSCMD_ARG_HOST_ARCH = 'x64'

'Portable Build Tools environment started.'
'* BUILD_TOOLS_ROOT   : {0}' -f $env:BUILD_TOOLS_ROOT
'* WindowsSDKDir      : {0}' -f $env:WindowsSDKDir
'* WindowsSDKVersion  : {0}' -f $env:WindowsSDKVersion
'* VCToolsInstallDir  : {0}' -f $env:VCToolsInstallDir
'* VSCMD_ARG_TGT_ARCH : {0}' -f $env:VSCMD_ARG_TGT_ARCH
'* VSCMD_ARG_HOST_ARCH: {0}' -f $env:VSCMD_ARG_HOST_ARCH

$env:INCLUDE = "$env:VCToolsInstallDir\include;$env:WindowsSDKDir\Include\$env:WindowsSDKVersion\ucrt;$env:WindowsSDKDir\Include\$env:WindowsSDKVersion\shared;$env:WindowsSDKDir\Include\$env:WindowsSDKVersion\um;$env:WindowsSDKDir\Include\$env:WindowsSDKVersion\winrt;$env:WindowsSDKDir\Include\$env:WindowsSDKVersion\cppwinrt"
$env:LIB = "$env:VCToolsInstallDir\lib\$env:VSCMD_ARG_TGT_ARCH;$env:WindowsSDKDir\Lib\$env:WindowsSDKVersion\ucrt\$env:VSCMD_ARG_TGT_ARCH;$env:WindowsSDKDir\Lib\$env:WindowsSDKVersion\um\$env:VSCMD_ARG_TGT_ARCH"
$env:BUILD_TOOLS_BIN = "$env:VCToolsInstallDir\bin\Hostx64\$env:VSCMD_ARG_TGT_ARCH;$env:WindowsSDKDir\bin\$env:WindowsSDKVersion\$env:VSCMD_ARG_TGT_ARCH;$env:WindowsSDKDir\bin\$env:WindowsSDKVersion\$env:VSCMD_ARG_TGT_ARCH\ucrt"
$env:PATH = "$env:BUILD_TOOLS_BIN;$env:PATH"
munohikari commented 1 day ago

@milnak please try the latest build and verify that it works as expected (it does not work for me on Windows 7, but i just copied your things so i wouldn't know how to fix it): https://github.com/Data-Oriented-House/PortableBuildTools/releases/tag/v2.4-pre