Keywords: Build, Windows, PowerShell based Building Scripts

Usages

How to setup building environment of MSCV (VC++)

.ps1:

if (!(Test-Path vswhere.exe)) {
  Invoke-WebRequest -Uri "https://github.com/microsoft/vswhere/releases/download/2.8.4/vswhere.exe" -OutFile vswhere.exe
}

# setup vsdevcmd.bat
# https://github.com/microsoft/vswhere/wiki/Find-VC
$path = .\vswhere.exe -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
if ($path) {
  $batpath = join-path $path 'Common7\Tools\vsdevcmd.bat'
  if (test-path $batpath) {
    cmd /s /c """$batpath"" $args && set" | Where-Object { $_ -match '(\w+)=(.*)' } | ForEach-Object {
      $null = new-item -force -path "Env:\$($Matches[1])" -value $Matches[2]
    }
  }
  # dbghelp.dll, administrator permission needed
  $debuggerpath = join-path $path 'Common7\IDE\Extensions\TestPlatform\Extensions\Cpp\x64\dbghelp.dll'
  if (!(Test-Path 'C:\Program Files (x86)\Windows Kits\10\Debuggers\x64')) {
    New-Item 'C:\Program Files (x86)\Windows Kits\10\Debuggers\x64' -ItemType Directory -Force
    Copy-Item $debuggerpath 'C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\dbghelp.dll'
  }
}

.bat:

@echo off

set PROTOBUF_ARCH=x64
set VSDEVCMD=C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat
if exist "%VSDEVCMD%" (
    @REM Tell VsDevCmd.bat to set the current directory, in case [USERPROFILE]\source exists. See:
    @REM C:\Program Files (x86)\Microsoft Visual Studio\%COMPILER%\Community\Common7\Tools\vsdevcmd\core\vsdevcmd_end.bat
     set VSCMD_START_DIR=%CD%
     call "%VSDEVCMD%" -arch=%PROTOBUF_ARCH%
      ) else (
     echo ERROR: Cannot find Visual Studio %COMPILER%
     exit /b 2
)

Reference

Examples

Building script of WebRTC:
https://github.com/crow-misia/libwebrtc-bin/blob/main/build.windows.ps1

Books

Book List

The PowerShell Scripting and Toolmaking Book
https://leanpub.com/powershell-scripting-toolmaking


“This defines entrepreneur and entrepreneurship - the entrepreneur always searches for change, responds to it, and exploits it as an opportunity.” ― Peter F. Drucker, Innovation and Entrepreneurship: Practice and Principles